I using a wrapper to the WCL BT library. Since the app is in .NET 4 and the license we have to the wrapper is in .NET 2, this is a sloppy workaround.
Using this wrapper with a .NET 4 WPF application works fine as long as the useLegacyV2RuntimeActivationPolicy
is on. More on this here. It takes around 22 seconds firing the OnDiscoveryComplete event.
But when using the same wrapper with an ASP NET MVC 3 application, the OnDiscoveryComplete event on the library is never fired. Anyone knows why?
The wrapper is called on buttonClickedEvent on the WPF app and on a SearchAsync action on an AsyncController on the MVC app.
The relevant code is here:
Calling the wrapper:
var wrapper = new Wrapper();
wrapper.Search();
Wrapper:
public Wrapper() {
_wclApi = new wclAPI();
_wclApi.Load();
_btDiscovery = new wclBluetoothDiscovery();
_btDiscovery.OnDiscoveryStarted += BtDiscoveryOnDiscoveryStarted;
_btDiscovery.OnDiscoveryComplete += BtDiscoveryOnDiscoveryComplete;
}
public void Search() {
var radios = new wclBluetoothRadios();
var ret = _btDiscovery.EnumRadios(radios);
if (ret == 0) {
wclBluetoothRadio radio = radios[0];
_btDiscovery.Discovery(radio, 0x15);
}
}
private void BtDiscoveryOnDiscoveryComplete(object sender, wclBluetoothDiscoveryCompleteEventArgs e) {
// handle devices found
}