从不同的线程启动/停止DispatcherTimer [英] Start/Stop DispatcherTimer from a different thread
本文介绍了从不同的线程启动/停止DispatcherTimer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是我的代码..
public DispatcherTimer tmr = new DispatcherTimer();
void somefunction (parameters){
if (something)
tmr.Start();
if (something else)
tmr.Stop();
}
我的问题是,我无法访问的开始/停止从第二个函数的TMR对象的方法,因为它运行在不同的线程!!!
My problem is that I can't access the Start/Stop methods of the tmr object from the second function since it runs on a different thread!!!
有人可以帮我?我打王氏这个问题近3天。 (
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())
这篇关于从不同的线程启动/停止DispatcherTimer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文