C#中的Timer和DispatcherTimer使用執行個體

來源:互聯網
上載者:User

標籤:zone   ott   write   tar   title   inf   運行   nta   間隔   

Timer組件是基於伺服器的計時器,通過設定時間間隔Interval,周期性的觸發Elapsed事件。


用法如下:


代碼如下:


class Program {

static System.Timers.Timer Timer1 = new System.Timers.Timer();

static void Main() {

Timer1.Interval = 1000;

Timer1.Elapsed += new ElapsedEventHandler(PeriodicTaskHandler);

Timer1.Start();

Console.ReadLine();

}

static void PeriodicTaskHandler(object sender, ElapsedEventArgs e) {

string str =Thread.CurrentThread.ManagedThreadId.ToString()+”##” +”Timer1″ +”##” + e.SignalTime.ToLongTimeString();

Console.WriteLine(str);

}

}

除聲明外, 跑步客文章均為原創,轉載請以連結形式標明本文地址
  C#中的Timer和DispatcherTimer使用執行個體

本文地址:  http://www.paobuke.com/develop/c-develop/pbk23181.html






相關內容C#中兩個byte如何相加C#操作本地檔案及儲存檔案到資料庫的基本方法總結利用TaskManager爬取2萬條代理IP實現自動投票功能WinForm實現程式一段時間不運行自動關閉的方法
C#中的Linq Intersect與Except方法使用執行個體C#開發的人臉左右相似性計算軟體源碼分析C#判斷當前程式是否通過管理員啟動並執行方法c#分頁讀取GB文字檔執行個體

C#中的Timer和DispatcherTimer使用執行個體

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.