C# UWP The application called an interface that was marshalled for a different thread

unity the application called an interface that was marshalled for a different thread
automation error the application called an interface that was marshalled for a different thread
python the application called an interface that was marshalled for a different thread
the application called an interface that was marshalled for a different thread ssis
c++ the application called an interface that was marshalled for a different thread

I have a C# UWP app that contains a function I want to call every 5 seconds. The function runs fine when called from a button, and the Timer write to the debug console fine every 5 seconds....When I call the function from the Timer, all heck breaks loose. I get this:

System.Exception was unhandled by user code HResult=-2147417842 Message=The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))

I assume your function touches the app's UI. Anything which touches the UI needs to run on the UI's dispatcher thread (most apps will have only one until you get into multiple window apps).

You can use a Windows.UI.Xaml.DispatcherTimer to run your timer on the dispatcher thread.

If you need to run code on a worker thread and then touch UI on the dispatcher thread you can call Dispatcher.RunAsync to marshal a call back onto the dispatcher thread.

You can generally find your dispatcher from your Window via Window.Dispatcher.

var ignored = Window.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
   // Do something on the dispatcher thread
});

https://social.msdn.microsoft.com/Forums/sqlserver, The application called an interface that was marshalled for a different thread. (​Exception from HRESULT: 0x8001010E  UWP SolidColorBrush - The application called an interface that was marshalled for a different thread exception. I have a UWP application that receives a dynamic updates via SignalR. I'm using Template10 and the SignalR listener is located in the ViewModel class. When messages are received by SignalR - the Model is updated.

Most likely you are using a Timer from System.Threading. That timer's events are not treated like a regular GUI event and if you are accessing a GUI item form the method invoked by that timer, it will cause issues since that thread is not the owner of the GUI item.

Use a Timer from System.Windows.Forms. That timer has access to your GUI items.

[UWP] Unhandled Exception: The application called an interface that , The application called an interface that was marshalled for a different thread | Stimulsoft Reports.UWP discussion. WinRT information: The application called an interface that was marshalled for a different thread. This is confusing since the point of CoreWindow.Dispatcher is to schedule the execution of code from a non-UI thread on to the UI thread.

You could actually use Observable.Interval from Reactive Extensions and specify explicitly on which dispatcher you want to observe timer events:

Observable.Interval(TimeSpan.FromSeconds(1), Scheduler.Default)
    .ObserveOn(coreWindow.Dispatcher)
    .Subscribe(_ => Log.Warning("Dispatcher.HasThreadAccess: " + coreWindow.Dispatcher.HasThreadAccess));

What I like about this approach is that you explicitly stating what happens on which thread (see SubscribeOn and ObserveOn).

The application called an interface that was marshalled for a , In other words, if you make a call from a UI thread to another thread application called an interface that was marshalled for a different thread. The exception thrown explains, “The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD)).” With DependencyObject ’s Dispatcher property of type CoreDispatcher , however, you can marshal a call back to the proper UI thread needed to update the TextBlock .

Universal Windows Apps with XAML and C# Unleashed: Threading , [UWP][C#]"The application called an interface that was marshalled for a And another method that is called whenever the "Ticked" event gets fired: https://​docs.microsoft.com/en-us/windows/uwp/threading-async/use-a-  Given the comment that it only happens once in a while, we can further deduce that the application called CoCreateInstance from a thread in a pool of worker threads, and attempted to use it in a function queued to that pool of threads (otherwise it would fail all the time and the author of the app would have found the problem).

[UWP][C#]"The application called an interface that was marshalled , This error Occur when you try to access an object in the UI from another task or thread in Windows 8 like if you are trying to change the text of a  UWP Multiple Views : The application called an interface that was marshalled for a different thread I am getting the error: The application called an interface that was marshalled for a different thread. When I create instances of a User Control in a UWP app with multiple views.

SfCart code behind, In my application we got 2 UWP pages (MainPage, SecondaryPage) The application called an interface that was marshalled for a different  The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD)) is raised at the only line in the following method in WorkScheduler.cs;

Comments
  • What kind of Timer are you using?
  • If you have a container other than a window, or your entire process is off-UI thread: container.Dispatcher.RunAsync(...) is a better bet. You can store this for later use, as far as I can tell.
  • Correct in principle but System.Windows.Forms in an UWP app seems unlikely.
  • @spender You mean it is not available in UWP?