C# 定時器定時更新的簡單實例
更新時間:2013年12月11日 09:43:22 作者:
這篇文章主要介紹了C#中定時器定時更新的簡單實例。需要的朋友可以過來參考下,希望對大家有所幫助
如下所示:
class Program
{
static void Main(string[] args)
{
//for (int i = 0; i < 100; i++)
//{
// SendMessage("13161626306", "13161626306");
//}
System.Timers.Timer aTimer = new System.Timers.Timer();
aTimer.Elapsed += new ElapsedEventHandler(aTimer_Elapsed);
// 設(shè)置引發(fā)時間的時間間隔 此處設(shè)置為1秒(1000毫秒)
aTimer.Interval = 300; //設(shè)置時間間隔
aTimer.Enabled = true;
Console.WriteLine("按回車鍵結(jié)束程序");
Console.WriteLine(" 等待程序的執(zhí)行......");
Console.ReadLine();
//SendMessage("13161626306", "13161626306");
}
static void aTimer_Elapsed(object sender, ElapsedEventArgs e)
{
SendMessage("13161626306", "13161626306");
}
private static void SendMessage(string PhoneNum, string Message)
{
try
{
using (ServiceReference1.WcfServiceClient sum = new ConsoleApplication1.ServiceReference1.WcfServiceClient())
{
ServiceReference1.MessageOk ok = new ConsoleApplication1.ServiceReference1.MessageOk();
ok.Message = Message;
ok.Phone = PhoneNum;
ServiceReference1.MessageOk NewMessage = sum.Ok(ok);
Console.WriteLine(NewMessage.Message);
Console.WriteLine("22");
//Console.ReadLine();
}
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
Console.ReadKey();
}
}
}
復(fù)制代碼 代碼如下:
class Program
{
static void Main(string[] args)
{
//for (int i = 0; i < 100; i++)
//{
// SendMessage("13161626306", "13161626306");
//}
System.Timers.Timer aTimer = new System.Timers.Timer();
aTimer.Elapsed += new ElapsedEventHandler(aTimer_Elapsed);
// 設(shè)置引發(fā)時間的時間間隔 此處設(shè)置為1秒(1000毫秒)
aTimer.Interval = 300; //設(shè)置時間間隔
aTimer.Enabled = true;
Console.WriteLine("按回車鍵結(jié)束程序");
Console.WriteLine(" 等待程序的執(zhí)行......");
Console.ReadLine();
//SendMessage("13161626306", "13161626306");
}
static void aTimer_Elapsed(object sender, ElapsedEventArgs e)
{
SendMessage("13161626306", "13161626306");
}
private static void SendMessage(string PhoneNum, string Message)
{
try
{
using (ServiceReference1.WcfServiceClient sum = new ConsoleApplication1.ServiceReference1.WcfServiceClient())
{
ServiceReference1.MessageOk ok = new ConsoleApplication1.ServiceReference1.MessageOk();
ok.Message = Message;
ok.Phone = PhoneNum;
ServiceReference1.MessageOk NewMessage = sum.Ok(ok);
Console.WriteLine(NewMessage.Message);
Console.WriteLine("22");
//Console.ReadLine();
}
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
Console.ReadKey();
}
}
}
相關(guān)文章
運(yùn)用示例簡單講解C#取消令牌CancellationTokenSource
這篇文章運(yùn)用示例簡單講解C#取消令牌CancellationTokenSource,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-08-08C#連接db2數(shù)據(jù)庫的實現(xiàn)方法
本篇文章是對C#連接db2數(shù)據(jù)庫的方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-05-05Windows下C#的GUI窗口程序中實現(xiàn)調(diào)用Google Map的實例
這篇文章主要介紹了Windows下C#的GUI窗口程序中實現(xiàn)調(diào)用Google Map的實例,如果只想調(diào)用瀏覽器打開網(wǎng)頁的話可以看文章最后的方法,需要的朋友可以參考下2016-04-04c#創(chuàng)建windows服務(wù)(Windows Services)詳細(xì)步驟
這篇文章主要介紹了c#創(chuàng)建windows服務(wù)(Windows Services)詳細(xì)步驟,大家參考使用吧2013-12-12C#利用SharpPcap實現(xiàn)網(wǎng)絡(luò)包捕獲嗅探
這篇文章主要為大家詳細(xì)介紹了C#利用SharpPcap實現(xiàn)網(wǎng)絡(luò)包捕獲嗅探,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-03-03C#實現(xiàn)字母與ASCII碼互相轉(zhuǎn)換
ASCII是基于拉丁字母的編碼系統(tǒng),也是現(xiàn)今最通用的單字節(jié)編碼系統(tǒng),本文主要為大家詳細(xì)介紹了如何使用C#實現(xiàn)字母與ASCII碼互轉(zhuǎn),需要的可以參考下2024-01-01