1
Vote

Connection to a device fails after a resume from suspend

description

Hey,

I'm running a WPF application on an MS Surface running Win8 x64 (.NET 4.0). After resuming from a full suspend (not just Connected Standby), client.Connect() starts throwing SocketException no matter if the device is available or not. It won't reconnect. Internally, WSAConnect() fails with return code 0xFFFFFFFF and lastError=10022, which reads "invalid argument was provided". If I close my application and restart it, the connection works immediately.

The connection runs in a background thread, where BluetoothClient attemts to be connected to a specific address, if it fails a SocketException is caught, the client is DISPOSED, recreated after a delay and attempts again.

To attempt to workaround, I've ensured that the client is closed and disposed on suspend entry by catching windows power events, and only resuming polling after the system has resumed. That has not had the expected influence.

I've made an API call dump from suspend entry up to resumed polling using WinAPIOverride64, which is included as an attachement. Note, that the first "closesocket" call is the socket being closed due to a suspend event, then lots of stuff is going on until the latest calls to WSAConnect being the reconnect attempt triggered by BluetoothClient.Connect().

file attachments

comments