【发布时间】:2013-03-24 11:10:47
【问题描述】:
大家有没有像 VB 一样的 c# 选项?
Sub Delay(ByVal dblSecs As Double)
Const OneSec As Double = 1.0# / (1440.0# * 60.0#)
Dim dblWaitTil As Date
Now.AddSeconds(OneSec)
dblWaitTil = Now.AddSeconds(OneSec).AddSeconds(dblSecs)
Do Until Now > dblWaitTil
Application.DoEvents() ' Allow windows messages to be processed
Loop
End Sub
【问题讨论】:
-
这是一个忙碌的等待 - 在众多延迟的方法中绝对是最糟糕的。
-
看起来你在做:
DateTime dblWaitTil = DateTime.Now.AddSeconds(dblSecs); while (DateTime.Now < dblWaitTil) { }。这将是一个非常“忙碌”(消耗资源)的循环。 -
为什么你要延迟?我问是因为您的回答可能会提示一个比简单延迟更好的解决方案。