radu-matei / websocket-manager

Real-Time library for ASP .NET Core
https://radu-matei.com/blog/real-time-aspnet-core/
MIT License
451 stars 182 forks source link

Can now call StartConnectionAsync multiple times to restore connections. #62

Closed Henry00IS closed 6 years ago

Henry00IS commented 6 years ago

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);
        }
    }
});