我的程序中有一個事件,其中值爲tantheta
的事件在後續事件觸發中不斷變化。在函數內計數3秒
問題是我必須檢查tantheta
這個值是否在0.6 to 1.5
的某個範圍內持續3秒的時間。
我用計時器嘗試過一些東西,但沒有成功。有什麼建議麼?
EDIT--
DispatcherTimer timer = new System.Windows.Threading.DispatcherTimer();
//This event is fired automatically 32 times per second.
private void SomeEvemt(object sender, RoutedEventArgs e)
{
tantheta = ; tantheta gets a new value here through some calculation
timer.Tick += new EventHandler(timer_Tick);
timer.Interval = new TimeSpan(0, 0, 5);
timer.Start();
//if condition to check if tantheta is within range and do something
}
void timer_Tick(object sender, EventArgs e)
{
DispatcherTimer thisTimer = (DispatcherTimer)sender;
textBox1.Text = thisTimer.Interval.ToString();
thisTimer.Stop();
return;
}
我要檢查是否tantheta值保持0.6內1.三秒鐘。我雖然計時器會是一個好方法,因爲它會阻止我的應用程序在所有這些計算過程中凍結,因爲它會轉到單獨的線程。 : -/
什麼,特別是,你試試? – 2012-02-10 05:23:33
爲什麼計時器不工作,你可以顯示你的代碼 – 2012-02-10 05:24:41
編輯帖子 – Cipher 2012-02-10 05:35:05