Using static UI methods with multithreading

I’m tackling small issues with calls to UI with C# Tasks. Basically, i have a task which is running and showing progress but can be interrupted via cancellation token and restarted with new params but for some reason when a task is canceled and the next one is launched i get an AccessViolationException.

Is there a way to lock some UI object to prevent access to early? Someone?

Can you provide some more information and a code sample? How are you accessing the UI?

I’d imagine you’d want to use Eto.Forms.Application.Instance.AsyncInvoke(); to change anything on the UI directly.

I found the way well and as you said Invoking was the “first suspect” to get in but my problem was that i tried to call thread dispatcher like Dispatcher.Current while task is running on other thread so i needed to shift to Application.Current.Dispatcher however having in mind this is bound to Win platform Eto one seems to be the proper solution to cover Win and Mac in oneliner - as long as you don’t bother with v5 :wink: I will mark your answer as a solution as it is easy and versatile :slight_smile:

Glad that works. You can run Eto on Rhino 5 (Windows) as well, you just need to do some embedding. On Rhino 6 & Mac I use Eto normally, for Rhino 5 I go Eto -> Wpf -> Winforms.

Though of course in this case you wouldn’t want to have Eto embedded in R5 just for the purposes of calling a static Rhino UI function.