2012-05-14 15 views
0

我是c#的新手。在計時器中放置一個方法來減慢Emotiv Epoc

問題

我想運行一個計時器中的一個方法,但該方法返回/不需要在設置參數的定時器參數。

原因:該方法被定期調用(EPOC Emotiv耳機),我希望它只被調用一次。

它是由一個函數調用(我認爲):

EmoEngine.Instance.CognitivEmoStateUpdated + =新EmoEngine.CognitivEmoStateUpdatedEventHandler(Instance_CognitivEmoStateUpdated);

運行方法(太經常)爲:

空隙Instance_CognitivEmoStateUpdated(對象發件人,EmoStateUpdatedEventArgs E) { EmoState ES = e.emoState; EdkDll.EE_CognitivAction_t currentAction = es.CognitivGetCurrentAction(); }

的sotware已經配備了一個計時器運行以處理事件每秒:

私人無效timer1_Tick(對象發件人,EventArgs的) { engine.ProcessEvents(); }

我希望我可以簡單地將方法aboce(Instance_Cogn ...)的定時器,我認爲這將SOVE問題 ..

什麼是做到這一點的最好辦法,請?

很多thx。

+0

根據你的帖子,你已經創建了一個事件「CognitivEmoStateUpdated」,當這個事件發生時您正在呼叫Instance_CognitivEmoStateUpdated功能。你想在一秒鐘內調用Instance_CognitivEmoStateUpdated,那麼綁定這個函數的意義是什麼? –

回答

1

使用System.Threading.Timer代替定時器控制。 線程的時間等級使您可以傳遞參數並在代碼中使用函數的輸出。

// 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); 

Refer the sample code

+0

感謝您的快速評論。 –

+0

不幸的是,當我使用時我得到一個CS0123錯誤:TimerCallback timeCB = new TimerCallback(Instance_CognitivEmoStateUpdated);雖然方法void Instance_CognitivEmoStateUpdated(object sender,EmoStateUpdatedEventArgs e) {}出現在那裏。我需要指定一個庫嗎? –

+0

在帖子中分享您的代碼。有多少個參數要傳遞給定時器。 –

相關問題