我目前正在开发一个应用程序,我想实现一个时间延迟.我不想使用System.Threading.Thread.Sleep(x); 当我读到这个停止线程(UI冻结)
我目前编写的代码是:
public void atimerdelay()
{
lblStat.Text = "In the timer";
System.Timers.Timer timedelay;
timedelay = new System.Timers.Timer(5000);
timedelay.Enabled = true;
timedelay.Start();
}
Run Code Online (Sandbox Code Playgroud)
我知道atimerdelay()确实被调用(使用lblStat),但它们没有5秒的延迟.我已经阅读了http://msdn.microsoft.com/en-us/library/system.timers.timer.aspx但我无法解释为什么上面的代码不起作用.
其他信息 - (为Hamlet Hakobyan添加)
该应用程序是一个"卡片检查器"应用程序(大学项目 - 不使用或存储真实信息).一旦用户填写了所有相关内容并单击"检查",就会调用验证方法列表.在调用其中任何一个之前,执行ping操作以确保计算机上有实时Internet连接.我想在ping和验证开始之间添加一点延迟.