8
是否可以檢查AutoResetEvent
實際對象的處理方式?它是通過超時還是通過從另一個方法調用Set()來觸發的?檢查AutoResetEvent狀態
這是我的代碼。
private AutoResetEvent autoResetEvent = new AutoResetEvent(false);
private int timeout = 30000;
public void SyncMethod()
{
// some code before
autoResetEvent.WaitOne(timeout);
// if autoResetEvent called by timeout then { do some stuff }
// some code after
}
public void AsyncMethod()
{
// some code before
// ok I am done
autoResetEvent.Set();
}
太容易了。 :) 謝謝! – 2012-07-17 08:13:08