-1

I am working on a asp.net mvc5 project and I want to implement chatroom with signalR So I got Microsoft.Aspnet.SignalR from nuget and I used a SignalR Hub class for hub and now i want to override OnDisconnected() method .but I get error 'ChatHub.OnDisconnected()': no suitable method found to override
I dont know how to solve this problem please help me

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.AspNet.SignalR;
using System.Collections.Concurrent;
using System.Threading.Tasks;

namespace WebApplication3.Hubs
{
    public class ChatHub : Hub
    {
        public void Hello()
        {
            Clients.All.hello();
        }
        static ConcurrentDictionary<string, string> dic = new ConcurrentDictionary<string, string>();

        public void Send(string name, string message)
        {
            Clients.All.broadcastMessage(name, message);
        }

        public void SendToSpecific(string name, string message, string to)
        {
            // Call the broadcastMessage method to update clients.
            Clients.Caller.broadcastMessage(name, message);
            Clients.Client(dic[to]).broadcastMessage(name, message);
        }

        public void Notify(string name, string id)
        {
            if (dic.ContainsKey(name))
            {
                Clients.Caller.differentName();
            }
            else
            {
                dic.TryAdd(name, id);
                foreach (KeyValuePair<String, String> entry in dic)
                {
                    Clients.Caller.online(entry.Key);
                }
                Clients.Others.enters(name);
            }
        }
        public override Task OnDisconnected()
        {
            var name = dic.FirstOrDefault(x => x.Value == Context.ConnectionId.ToString());
            string s;
            dic.TryRemove(name.Key, out s);
            return Clients.All.disconnected(name.Key);
        }
    }
}
myname
  • 1,159
  • 2
  • 8
  • 9

1 Answers1

1

For SignalR 2.1.0+, you need to use OnDisconected(bool stopCalled).

// Microsoft.AspNet.SignalR.Hub
// Summary:
//     Called when a connection disconnects from this hub gracefully or due to a timeout.
//
// Parameters:
//   stopCalled:
//     true, if stop was called on the client closing the connection gracefully; false,
//     if the connection has been lost for longer than the Microsoft.AspNet.SignalR.Configuration.IConfigurationManager.DisconnectTimeout.
//     Timeouts can be caused by clients reconnecting to another SignalR server in scaleout.
//
// Returns:
//     A System.Threading.Tasks.Task
public virtual Task OnDisconnected(bool stopCalled);
Florin Secal
  • 931
  • 5
  • 15