开发者

Start/Stop DispatcherTimer from a different thread

开发者 https://www.devze.com 2023-04-12 02:13 出处:网络
Here is my code.. public DispatcherTimer tmr = new DispatcherTimer(); void somefunction (parameters){ if (something)

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 can't a开发者_运维百科ccess the Start/Stop methods of the tmr object from the second function since it runs on a different thread!!!

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


You need to Invoke it via Dispatcher (for marshaling the call from another thread) like so

Deployment.Current.Dispatcher.BeginInvoke((Action)(()=>timer.Start())
0

精彩评论

暂无评论...
验证码 换一张
取 消