在Windows Forms中是否有与Qt库中的以下静态函数类似的模拟函数?
http://doc.qt.io/qt-5/qtimer.html#singleShot
我能想到的最好的方式是以下内容:
ThreadPool.QueueUserWorkItem((o) =>
{
Thread.Sleep(someNumberOfMilliseconds);
DoDelayedWorkHere();
});
更新
使用System.Windows.Forms.Timer可以解决这个问题。
var timer = new System.Windows.Forms.Timer();
timer.Interval = someNumberOfMilliseconds;
timer.Tick += (o, args) =>
{
timer.Stop();
DoDelayedWorkHere();
};
timer.Start();