Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SignalR overwriting OnConnected(), OnDisconnected()

I'm trying to overwrite OnConnected(), OnDisconnected() methods but I get:

OnConnected()': no suitable method found to override

Is implementing IDisconnect, IConnect interfaces and doing my processing within Connect() and Disconnect() the same as OnConnected(), OnDisconnected()?

what gives?

public static class UserHandler
{
    public static HashSet<string> ConnectedIds = new HashSet<string>();
}

public class MyHub : Hub
{
    public override Task OnConnected()
    {
        UserHandler.ConnectedIds.Add(Context.ConnectionId);
        return base.OnConnected();
    }

    public override Task OnDisconnected()
    {
        UserHandler.ConnectedIds.Remove(Context.ConnectionId);
        return base.OnDisconnected();
    }
}
like image 909
ShaneKm Avatar asked Nov 23 '12 06:11

ShaneKm


1 Answers

This code worked for me until this morning when I upgraded SignalR from 2.1.0 to 2.1.1, and now I get "no suitable method found to override" for OnDisconnected(). I believe it needs to be written like this instead to account for a new parameter:

public override Task OnDisconnected(bool stopCalled = true) 
{
   UserHandler.ConnectedIds.Remove(Context.ConnectionId);
   return base.OnDisconnected(stopCalled); 
}
like image 146
brnwdrng Avatar answered Oct 13 '22 22:10

brnwdrng