0

I am facing a bit of an issue with signalr client connectivity. I am using longpolling transport to create a connection between my server and a .net based client. After a while(some six, seven hours) the connection dies and the client throws an error. I am trying to re-establish a connection as follows:

void hubConnection_Error(Exception obj)
    {
        System.Windows.Application.Current.Dispatcher.Invoke(
     System.Windows.Threading.DispatcherPriority.Normal,
     (Action)delegate()
     {
         this.hubConnection.Start(new LongPollingTransport()).Wait(5000);
     });
    }

Is this a good approach? I am still trying to figure out the issue on the server side, but until then will this re-establish the connection once the error occurs?

Many thanks.

aliirz
  • 1,008
  • 2
  • 13
  • 25

1 Answers1

0

You'd be better off handling the Closed event on the connection and then restarting it.

AKA

this.hubConnection.Closed += () => {
    // Restart your connection
};

This way whenever your connection stops you can just re-instantiate it (this is the recommended way).

N. Taylor Mullen
  • 18,061
  • 6
  • 49
  • 72