That is, without it crashing. This will allow people to write a simple loop like this to keep connections alive forever whenever they drop:
// infinite loop that attempts to re-establish the connection if it's ever lost.
Task.Run(async () =>
{
while (true)
{
try
{
await Connection.StartConnectionAsync("ws://localhost:5000/chat");
}
catch
{
// ignore exception and establish another connection in a second.
System.Threading.Thread.Sleep(1000);
}
}
});
That is, without it crashing. This will allow people to write a simple loop like this to keep connections alive forever whenever they drop: