locked
Cannot implicitly convert type 'System.Threading.Tasks.Task<object>' to 'string' RRS feed

  • Question

  • User932259438 posted

    Hi,

    Do you have any idea?
    I got this error: Cannot implicitly convert type 'System.Threading.Tasks.Task<object>' to 'string' in line:

     return context.Clients.All.RecieveNotification(totalNewMessages);

      
    
    public string SendNotifications()
        {
            using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString))
            {
                string query = "SELECT  NewMessageCount FROM [dbo].[Modeling_NewMessageNotificationCount]";
                connection.Open();
                using (SqlCommand command = new SqlCommand(query, connection))
                {
                    try {
                    command.Notification = null;
                    DataTable dt = new DataTable();
                    SqlDependency dependency = new SqlDependency(command);
                    dependency.OnChange += new OnChangeEventHandler(dependency_OnChange);               
                    if (connection.State == ConnectionState.Closed)
                        connection.Open();
                    var reader = command.ExecuteReader();
                    dt.Load(reader);
                    if (dt.Rows.Count > 0)
                    {
                        totalNewMessages =Int16.Parse(dt.Rows[0]["NewMessageCount"].ToString());
                       // totalNewCircles = Int16.Parse(dt.Rows[0]["NewCircleRequestCount"].ToString());
                       // totalNewJobs = Int16.Parse(dt.Rows[0]["NewJobNotificationsCount"].ToString());
                       // totalNewNotification = Int16.Parse(dt.Rows[0]["NewNotificationsCount"].ToString());
                    }
                    connection.Close();
                }
                catch(Exception ex)
                {
                    throw;
                }
                }
            }
            IHubContext context = GlobalHost.ConnectionManager.GetHubContext<NotificationHub>();
            return context.Clients.All.RecieveNotification(totalNewMessages);
        }
    Friday, December 29, 2017 10:20 PM

Answers

All replies