doghappy / socket.io-client-csharp

socket.io-client implemention for .NET
MIT License
721 stars 124 forks source link

App terminates with no exceptions after running await client.ConnectAsync() #294

Open liorsbg opened 2 years ago

liorsbg commented 2 years ago

On the server side I see a connection and then disconnection immediately after. Looks like we're not really awaiting...

Happened here as well: #291 #287

doghappy commented 1 year ago

sorry, I can't get the point, could you explain more?

larryr1 commented 1 year ago

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.

shad0w-jo4n commented 1 year ago

Уou can still do this in async Main method:

await Task.Delay(Timeout.Infinite);