I am developing a windows service which starts listenning the bluetooth connection when it is run using the following code:
btListener = new BluetoothListener(service);
If the service is started manually after Windows completes the startup (says after the Windows starts for around 5 minutes), then, everything works fine: the Bluetooth service is started successfully.
However, if I set the Windows service's startup type to automatic, that part of code causes the following exception:
System.Net.Sockets.SocketException (0x80004005): An invalid argument was supplied
at InTheHand.Net.Bluetooth.Msft.SocketBluetoothClient.ThrowSocketExceptionForHR(Int32 errorCode)
at InTheHand.Net.Bluetooth.Msft.MicrosoftSdpService.SetService(Byte sdpRecord, ServiceClass cod)
at InTheHand.Net.Bluetooth.Msft.WindowsBluetoothListener.SetService(Byte sdpRecord, ServiceClass cod)
at InTheHand.Net.Bluetooth.Msft.WindowsBluetoothListener.Start(Int32 backlog)
I am thinking that is because the "Start" method is called too soon when the Bluetooth device is not yet initialized. Is there anyone also encountering this similar problem? Any idea on how to know when the "Start" method should be called
to ensure it can start successfully?
Appreciate on any feedback or comments.