c# timer问题
来源:百度知道 编辑:UC知道 时间:2024/05/16 14:44:48
执行TIMER1。START()5秒钟后执行TIMER1。STOP()
Timer1.Interval = 5000;
然后在Timer1的Tick事件里写Timer1.Stop();
对楼主要干什么不太了解,不知道是不是这个意思.
Threading.Sleep(5000);
等5秒钟后才执行....(不知道有没有拼错,请自已测试)
Tick事件里触发一下STOP()呢
下面的代码示例实现简单的间隔计时器,该计时器每五秒钟发一次警报。当发生警报时,MessageBox 显示该警报已激活的次数合计并询问用户计时器是否应继续运行。
public class Class1 {
static System.Windows.Forms.Timer myTimer = new System.Windows.Forms.Timer();
static int alarmCounter = 1;
static bool exitFlag = false;
// This is the method to run when the timer is raised.
private static void TimerEventProcessor(Object myObject,
EventArgs myEventArgs) {
myTimer.Stop();
// Displays a message box asking whether to continue running the timer.
if(MessageBox.Show("Continue running?", "Count is: " + alarmCounter,
MessageBoxButtons.YesNo) == DialogResult.Yes) {
// Restarts the tim