C# 簡單的定時器使用


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
System.Timers.Timer t = new System.Timers.Timer(1000);//實例化Timer類,設置間隔時間為1000毫秒;

t.Elapsed += new System.Timers.ElapsedEventHandler(theout);//到達時間的時候執行事件;

t.AutoReset = true;//設置是執行一次(false)還是一直執行(true);

t.Enabled = true;//是否執行System.Timers.Timer.Elapsed事件;
}

public void theout(object source, System.Timers.ElapsedEventArgs e)
{

MessageBox.Show("OK!");

}
}
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM