我试图通过使用计时器来延迟我的方法:
private System.Timers.Timer _delayTimer;
private void delay()
{
_delayTimer = new System.Timers.Timer();
_delayTimer.Interval = 5000;
//_delayTimer.Enabled = true;
_delayTimer.Elapsed += _delayTimer_Elapsed;
_delayTimer.Start();
someMethod();
}
}
private void _delayTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
// delay for 5 seconds
}
当我进入delay()
方法时,我想启动计时器,而不是我想要 5 秒的延迟,然后才想执行someMethod()
,目前这不会发生,在执行后delay()
没有someMethod()
5 秒的延迟