c#语⾔中怎么实现延时功能,C# 延时实现满意答案
GVHN11111
2013.09.07
采纳率:46%    等级:12
已帮助:8027⼈
Timer控件
Timer.Enabled 属性⽤于设置是否启⽤定时器
Timer.Interval 属性,事件的间隔,单位毫秒
Timer.Elapsed 事件,达到间隔时发⽣。
例⼦:
public class Timer1
{
public static void Main()
{
System.Timers.Timer aTimer = new System.Timers.Timer();
aTimer.Elapsed+=new ElapsedEventHandler(OnTimedEvent);
// Set the Interval to 5 seconds.
aTimer.Interval=5000;
aTimer.Enabled=true;
Console.WriteLine("Press \'q\' to quit the sample.");
while(Console.Read()!='q');
}
// Specify what you want to happen when the Elapsed event is raised.
writeline方法的作用
private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
Console.WriteLine("Hello World!");
}
}
10分享举报

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。