I am trying to use a GraphicsCapturePicker
from the code-behind in a MAUI
app and am hitting a COM exception implying I am calling this from the wrong thread. Typically code in WPF/XAML code-behind files are dispatched from the main thread so I am a bit confused about what's going wrong here:
// A regular button event handler in MainPage.xaml.cs
private void OnScreenCaptureClicked(object sender, EventArgs e)
{
var picker = new GraphicsCapturePicker();
GraphicsCaptureItem item = picker.PickSingleItemAsync().GetResults();
}
Throws exception:
"The application called an interface that was marshalled for a different thread"
Exception thrown: 'System.Runtime.InteropServices.COMException' in System.Private.CoreLib.dll
Note: In the above example I am calling the method syncronously as a test to make it easier to catch the exception, the same thing happens when it's wrapped in a task.
This exact code works fine in a regular non-MAUI UWP/C# project.