Start / Stop DispatcherTimer from another thread

Here is my code ..

public DispatcherTimer tmr = new DispatcherTimer(); void somefunction (parameters){ if (something) tmr.Start(); if (something else) tmr.Stop(); } 

My problem is that I cannot access the Start / Stop methods of the tmr object from the second function, since it works in another thread !!!

Can someone please help me ?? I am struck by this problem for almost 3 days !: (

+6
source share
1 answer

You need to call it through the dispatcher (to march a call from another thread) so

 Deployment.Current.Dispatcher.BeginInvoke((Action)(()=>timer.Start()) 
+2
source

Source: https://habr.com/ru/post/898951/


All Articles