C#如何做一个5秒间隔的无限循环?
如何用一个按钮控制跳出?
[解决办法]
简易的↓
new Thread()
while(true){
//你的代码
Thread.Sleep(5000)
}
[解决办法]
void Application_Start(object sender, EventArgs e) { //在应用程序启动时运行的代码 checkTimer = new System.Timers.Timer(); inProgss = false; checkTimer.Interval = 5000; checkTimer.Elapsed += new System.Timers.ElapsedEventHandler(checkTimer_Elapsed); } private System.Timers.Timer checkTimer; private bool inProgss = false; void checkTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { if (!inProgss) { inProgss = true; //执行需要的代码 inProgss = false; } }