C#使用timer定時在屏幕上輸出信息的方法
更新時間:2015年03月31日 09:49:03 作者:songguo
這篇文章主要介紹了C#使用timer定時在屏幕上輸出信息的方法,涉及C#中timer定時器的使用技巧,具有一定參考借鑒價值,需要的朋友可以參考下
本文實例講述了C#使用timer定時在屏幕上輸出信息的方法。分享給大家供大家參考。具體分析如下:
這段c#代碼通過timer定時器每隔5秒鐘調(diào)用一次OnTimerElapsed事件,在屏幕上輸出信息,這是一個簡單的timer定時器使用范例,可以大概了解一些C#中timer的用法
using System; using System.Timers; public class Program { private static System.Timers.Timer testTimer; public static void Main(string[] args) { testTimer = new System.Timers.Timer(5000); // 5 seconds testTimer.Elapsed += new ElapsedEventHandler(OnTimerElapsed); testTimer.Interval = 5000; testTimer.Enabled = true; Console.WriteLine("Press the enter key to stop the timer"); Console.ReadLine(); } private static void OnTimerElapsed(object source, ElapsedEventArgs e) { Console.WriteLine("Timer elapsed at {0}", e.SignalTime); } }
希望本文所述對大家的C#程序設計有所幫助。
相關文章
C#解決SQlite并發(fā)異常問題的方法(使用讀寫鎖)
這篇文章主要介紹了C#解決SQlite并發(fā)異常問題的方法,通過使用讀寫鎖達到多線程安全訪問,進而解決SQLite并發(fā)異常的問題,具有一定參考借鑒價值,需要的朋友可以參考下2016-07-07使用GetInvalidFileNameCharts生成文件名
這篇文章主要介紹了一個很實用的函數(shù)Path.GetInvalidFileNameCharts(),他可以很方便的生成一個有效的文件名稱2014-01-01