Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting BluetoothRadio.Mode in WPF app produces an exception #432

Open
MariusMichelPrimes opened this issue Sep 11, 2024 · 0 comments
Open

Comments

@MariusMichelPrimes
Copy link

I want to do something like this:

  var myRadio = BluetoothRadio.Default;
  var mode = myRadio.Mode;

  if (mode != RadioMode.Connectable)
  {  
      // produces an exception, as the lib uses a Windows RT Dispatcher function
      myRadio.Mode = RadioMode.Connectable;
  }

Code from BluetoothRadio.Windows, where the Windows.UI.Core.CoreWindow.GetForCurrentThread() returns null.

public RadioMode Mode
{
    get
    {
        return _radio.State == RadioState.On ? RadioMode.Connectable : RadioMode.PowerOff;
    }
    set
    {
        Windows.UI.Core.CoreWindow.GetForCurrentThread().DispatcherQueue.TryEnqueue(async () =>
            {
                if (await Radio.RequestAccessAsync() == RadioAccessStatus.Allowed)
                {
                    await _radio.SetStateAsync(value == RadioMode.PowerOff ? RadioState.Off : RadioState.On);
                }
            });
    }
}

I suppose, that this would be a problem in a console app, too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant