I need to reconnect Client app (SignalR) to the Server app (SignalR) until it is connected.
But it has ConnectionState.Reconnecting
always... So I have no clue how to reconnect.
I found this approach Best practice for reconnecting SignalR 2.0 .NET client to server hub
saying we have to recreate HubConnection
as a unique working approach...
Any clue?
The code I have is
System.Timers.Timer connectionChecker = new System.Timers.Timer(20000);
HubConnection Connection { get; set; }
private void ConnectionChecker_ElapsedAsync(object sender, System.Timers.ElapsedEventArgs e)
{
if (Connection.State == ConnectionState.Disconnected)
{
connectionChecker.Stop();
ForceConnectAsync().Start(); // In this method await Connection.Start();
}
else if (Connection.State == ConnectionState.Connecting)
{
// After conection lost it keeps this state ALWAYS.
// But once server is up it still has this state.
}
else if (Connection.State == ConnectionState.Reconnecting)
{
}
else if (Connection.State == ConnectionState.Connected)
{
}
}