Pergunta

I am working on a .net client application which utilizes SignalR. I want to notify the user if the connection is down for some reason. How can I capture the disconnect event using the native client?

Foi útil?

Solução

The client will go into the reconnecting when the connection dies.

Therefore you can tie into the Reconnecting event to see when the connection goes down:

var connection = new Connection("http://myEndPointURL");

connection.Reconnecting += () =>
{
    Console.WriteLine("The connection has gone down, shifting into reconnecting state");
};

Hope this helps!

Outras dicas

I was able to capture StateChanged to detect changes in the connection and notify the user.

        connection.StateChanged += (statechange) =>
            {
                Console.WriteLine("Changing from " + statechange.OldState + " to " + statechange.NewState);
            };

This gives me a mechanism to notify the user when the connection is dropped or successfully reconnected.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top