2011-10-18 9 views
3

WindowsフォームのQtライブラリの次の静的関数のアナログはありますか?QTimer :: singleShotはC#Windows Formsに相当しますか?

ThreadPool.QueueUserWorkItem((o) => 
{ 
    Thread.Sleep(someNumberOfMilliseconds); 
    DoDelayedWorkHere(); 
}); 

UPDATE

これはSystem.Windows.Forms.Timerを使用してトリックを行います。

http://doc.qt.io/qt-5/qtimer.html#singleShot

私が思い付くことができる最高は次のとおりです。

var timer = new System.Windows.Forms.Timer(); 
timer.Interval = someNumberOfMilliseconds; 
timer.Tick += (o, args) => 
    { 
     timer.Stop(); 
     DoDelayedWorkHere(); 
    }; 
timer.Start();   

答えて

6

QTimerはWinforms Timerと同様に同期タイマーです。スレッディングまたは他のTimerクラスの1つは、ではなく、代用です。単一ショットは実装が簡単です。TickイベントハンドラでタイマーのEnabledプロパティをfalseに設定するだけです。レースの危険性なし:

private void timer1_Tick(object sender, EventArgs e) { 
     ((Timer)sender).Enabled = false; 
     // etc.. 
    } 
関連する問題