rdavisau / sockets-for-pcl

Cross-platform socket API for Xamarin iOS/Android/Forms, Xamarin.Mac/MonoMac, Windows Phone 8/8.1, Windows Store and Windows Desktop.
MIT License
224 stars 72 forks source link

ConnectAsync with CancellationToken hangs #137

Open vbisbest opened 7 years ago

vbisbest commented 7 years ago

On iOS, it appears that using a cancellationtoken locks up the app and just hangs when the socket is really waiting to timeout. Here is the code:

` socket = new TcpSocketClient();

            cts = new CancellationTokenSource();
            cts.CancelAfter(10000);

            task = socket.ConnectAsync(serverInfoState.Server.RealIP, serverInfoState.Server.RealPort, false, cts.Token);
           await task;`

Am I using the token incorrectly? Connecting to a server that I know is unavailable causes the behavior. In the above code, the app remains responsive for 10 seconds, the it locks up for about another 30 seconds and eventually throws the cancellation error.

sushibear commented 6 years ago

Same on UWP it seems..

Any code after using ConnectAsync is not beeing called. It hangs and does not throw any error or warning for me.