websocket-sharp
websocket-sharp copied to clipboard
Keep Client Connection Open
Hey, @dommy1C! Here's a way to reconnect until the connection is available again.
ws.OnClose += (sender, e) =>
{
Task.Run(() =>
{
while (ws.IsAlive == false)
{
Thread.Sleep(1000); // time to wait before trying to reconnect in milliseconds
ws.Connect();
}
});
};
Hey, @dommy1C! Here's a way to reconnect until the connection is available again.
ws.OnClose += (sender, e) => { Task.Run(() => { while (ws.IsAlive == false) { Thread.Sleep(1000); // time to wait before trying to reconnect in milliseconds ws.Connect(); } }); };
Instead of Thread.Sleep(1000);
You should use Task.Delay(1000).Wait();
Wow, thanks so much! The solution I proposed was giving some problems blocking the app's main thread at times.
Wow, thanks so much! The solution I proposed was giving some problems blocking the app's main thread at times.
Glad it helped. :)