Is there an analog to the following static function from the Qt library in Windows Forms?
http://doc.qt.io/qt-5/qtimer.html#singleShot
The best I can come up with is the following:
ThreadPool.QueueUserWorkItem((o) =>
{
Thread.Sleep(someNumberOfMilliseconds);
DoDelayedWorkHere();
});
UPDATE
This does the trick using System.Windows.Forms.Timer.
var timer = new System.Windows.Forms.Timer();
timer.Interval = someNumberOfMilliseconds;
timer.Tick += (o, args) =>
{
timer.Stop();
DoDelayedWorkHere();
};
timer.Start();
QTimer is a synchronous timer, just like the Winforms Timer. Threading or one of the other Timer classes is not a substitute. A single-shot is easy to implement, just set the timer’s Enabled property to false in the Tick event handler. No danger of a race: