0

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
}
Community
  • 1
  • 1
dcarneiro
  • 7,060
  • 11
  • 51
  • 74

1 Answers1

0

There is probably an exception that the wclBluetoothDiscovery is encountering but not properly exposing to you. It's a common bug in async APIs to not inform callers when bad things happen... the proper API design would be to raise the *Complete event but then raise the exception to you when you query the completed event args.

Robert Levy
  • 28,747
  • 6
  • 62
  • 94
  • The line _btDiscovery.Discovery(radio, 0x15); is returning 0. So it's not on the Discovery method. Maybe on the callback. – dcarneiro Oct 20 '11 at 16:50
  • @Daniel, if the Discovery method is async (it just kicks off a background process to do the actual work and then returns immediately) then the hidden exception would be in that background process and occurs after you get the 0 return value – Robert Levy Oct 20 '11 at 16:55
  • @Daniel, also why the heck do you have a web app doing bluetooth discovery? – Robert Levy Oct 20 '11 at 16:55
  • It's a backoffice App to work on a LAN environment so the devices he's searching will in fact be there. – dcarneiro Oct 20 '11 at 16:58
  • Well, I guess it's really a bug with the WCL library – dcarneiro Oct 21 '11 at 15:03