socket.io-client-csharp
socket.io-client-csharp copied to clipboard
App terminates with no exceptions after running await client.ConnectAsync()
On the server side I see a connection and then disconnection immediately after.
Looks like we're not really await
ing...
Happened here as well: #291 #287
sorry, I can't get the point, could you explain more?
client.ConnectAsync()
is non-blocking no matter how you call it so unless you have something keeping your app running, it will terminate. I fixed this by just running a thread in the foreground. I create the thread after initializing the rest of my app and connecting the socket.
Thread keepAliveThread = new Thread(() =>
{
Thread.CurrentThread.IsBackground = false;
while (true)
{
Thread.Sleep(1000);
}
});
keepAliveThread.Start();
This is only necessary for me because my program will run in the context of a background process with no user interaction and will not have a terminal. If you have a console, you can do something like Console.ReadLine()
to resolve the problem as stated in your reference issues.
Уou can still do this in async Main
method:
await Task.Delay(Timeout.Infinite);