我有一個應用程序,其中一個類我正在初始化Windows Form
和System.Threading.Timer
。問題與System.Threading.Timer和模式ShowDialog()
如果timer
,這使一些IPC
基礎的東西檢查,遇到一個特定的值,它標誌着在同一個班級,然後更早初始化的對話框上調用ShowDialog()
一個event
。
不幸的是,這個ShowDialog()
是Modal
,停止計時器。
我的印象是System.Threaded.Timer
是在與調用線程不同的線程中創建的,因此Timer將繼續在後臺運行。
編輯 - 一些代碼
public delegate void EventHandler();
class someClass
{
WrapperForm dlg = null;
public void CallToChildThread(Object stateInfo)
{
AutoResetEvent autoEvent = (AutoResetEvent)stateInfo;
//Check IPC
//Fire event
_show.Invoke();
}
public someClass()
{
public static event EventHandler _show;
initializeDialog(); // Initialize the dialog. Standard new
var autoEvent = new AutoResetEvent(false);
var stateTimer = new System.Threading.Timer(CallToChildThread,
autoEvent, 1000, 250);
_show += new EventHandler(eventCheck);
}
void eventCheck()
{
//If some condition
dlg.ShowDialog(); //Timer stops
}
}
這怎麼可能解決?
如果您可以讓我們看看您嘗試過的(某些代碼)會很棒。 – EpicKip
模態不會爲我停止計時器o.O – EpicKip
添加了一些代碼。 – user1173240