我是c#的新手。
问题:
我想在计时器中运行一个方法,但是该方法返回/需要参数,而不是在计时器集合中。
的原因:这个方法是定期调用的( Emotiv耳机),我希望它每秒钟只调用一次。
它被称为(我认为)由一个函数:
新EmoEngine.CognitivEmoStateUpdatedEventHandler(Instance_CognitivEmoStateUpdated);EmoEngine.Instance.CognitivEmoStateUpdated +=
运行(太频繁)的方法是:
void Instance_CognitivEmoStateUpdated(对象发送方,EmoStateUpdatedEventArgs e) { EmoState es = e.emoState;EdkDll.EE_CognitivAction_t currentAction = es.CognitivGetCurrentAction();}
软件已经配备了计时器,每秒钟运行一次以处理事件:
私有空timer1_Tick(对象发送方,EventArgs e) { engine.ProcessEvents();}
我希望我能简单地把方法放在上面(Instance_Cogn.)在计时器上,我想这会使问题..。
这样做最好的方法是什么?
很多东西。
发布于 2012-05-14 15:16:46
使用System.Threading.Timer代替计时器控制。线程的Time类为您传递参数和在代码中使用函数的输出提供了便利。
// Create the delegate that invokes methods for the timer.
TimerCallback timerDelegate = new TimerCallback(CheckStatus);
// Create a timer that waits one second, then invokes every second.
Timer timer = new Timer(timerDelegate, arguments,1000, 1000);参考示例代码
https://stackoverflow.com/questions/10585986
复制相似问题