I have a Miracast receiver Winform application which uses the Microsoft.Toolkit.Forms.UI.Controls package to access the Windows.Media.Miracast Namespace.

I have used to following code to start the miracast receiver.

public MiracastReceiverSession currentSession;
currentSession = castReceiver.CreateSession();
                    currentSession.AllowConnectionTakeover = false;
                    currentSession.MaxSimultaneousConnections = 3;
                    currentSession.ConnectionCreated += OnSessionConnectionCreated;
                    currentSession.MediaSourceCreated += OnSessionMediaSourceCreated;
                    currentSession.Disconnected += OnSessionDisconnect;
MiracastReceiverSessionStartResult startResult = currentSession.Start();

Connection is successfully established from both my Windows and Android devices and the screen is shared properly. But when I access the MiracastReceiverVideoStreamSettings in the OnSessionMediaSourceCreated event I am getting the following error message.

I get the error when the breakpoint is hit

The error is as follows

System.Exception: The application called an interface that was marshalled for a different thread. (0x8001010E (RPC_E_WRONG_THREAD)) at Windows.Media.Miracast.MiracastReceiverStreamControl.GetVideoStreamSettings() at ImmersiveMiracast.Core.MiracastReceiverWrapper.<>c__DisplayClass59_0.b__0() in D:\Projects\miracast\dev\unify-miracast\ImmersiveMiracast\ImmersiveMiracast\Core\MiracastReceiverWrapper.cs:line 610 at System.Windows.Threading.Dispatcher.Invoke(Action callback, DispatcherPriority priority, CancellationToken cancellationToken, TimeSpan timeout) at System.Windows.Threading.Dispatcher.Invoke(Action callback) at ImmersiveMiracast.Core.MiracastReceiverWrapper.Invoke(Action a)

I have tried using System.Windows.Threading.Dispatcher Invoke(Action) and Application.Current.Dispatcher.Invoke(Action) but the result is the same.

0

There are 0 answers