Avatar of thready
thready
 asked on

thread requesting invalidate on ui thread c#

hi experts,
I have a thread that is moving objects around in a canvas by changing their coordinates when events happen.  normally if I was doing all this on the ui thread, there's no problem to call invalidate whenever I want to redraw.  but of course this blows up from the thread if invalidate is called from it.

could someone show me a little snippet that would show how to use the synchronization context to call invalidate from my thread?  this worker was started with task.factory.startnew(MoveObjectsAround)

Thanks!
C#Microsoft Development.NET Programming

Avatar of undefined
Last Comment
thready

8/22/2022 - Mon
Fernando Soto

Hi  thready;

You will need to use the Dispatcher to access the controls of the UI thread. Please read this article on how to do this in your application.

How to Use Dispatcher in WPF to Build Responsive Applications
thready

ASKER
Thanks Fernando but I'm not using wpf. I'm using Xamarin, so I think my only option is vanilla synchronization context.
Fernando Soto

Not stated in your question.
Your help has saved me hundreds of hours of internet surfing.
fblack61
thready

ASKER
Sorry about that, but I did ask for synchronization context at least :-)
ASKER CERTIFIED SOLUTION
Mike Tomlinson

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
thready

ASKER
Thank you!