WindowsAppSDK
WindowsAppSDK copied to clipboard
MediaSource.OpenAsync fails with 'A delegate was assigned when not allowed' when called simultaneously on different threads
Describe the bug
MediaSource.OpenAsync fails with 'A delegate was assigned when not allowed' when called simultaneously on different threads. Looks like the MediaSource internally has this sort of error - https://devblogs.microsoft.com/oldnewthing/20210226-00/?p=104911#:~:text=The%20description%20of%20this%20error,callback%20has%20already%20been%20set.
Steps to reproduce the bug
Partial code
MediaSource newMediaSource = null;
try {
newMediaSource = MediaSource.CreateFromStorageFile(file);
}catch (Exception) { }
if(newMediaSource == null) {
return;
}
var t1 = newMediaSource.OpenAsync();
var t2 = Task.Run(async () => {
await newMediaSource.OpenAsync();
});
await Task.WhenAll(t1.AsTask(), t2);
Expected behavior
No exception.
Screenshots
No response
NuGet package version
None
Packaging type
Packaged (MSIX)
Windows version
Windows 11 version 22H2 (22621, 2022 Update)
IDE
Visual Studio 2022
Additional context
Bug is in Windows.Media.Core.MediaSource. WinAppSDK is not required.