我開發(fā)了一個(gè) Windows 服務(wù),用于將文件從一個(gè)位置復(fù)制到另一個(gè)位置。由于我需要在后臺運(yùn)行服務(wù),因此有必要實(shí)現(xiàn)計(jì)時(shí)器功能。服務(wù).cs protected override void OnStart(string[] args) { //OnStart(new string[0]); } public void Start() { timer1 = new Timer(); this.timer1.Interval = 30000; //every 30 seconds 41 ***this.timer1.Elapsed += new System.Timers.ElapsedEventHandler(this.mysql);*** timer1.Enabled = true; 43 mysql(); } static void mysql() { **File copy code included in this function. }上面提到的第 41 行中的錯(cuò)誤觸發(fā)是,“mysql”沒有重載匹配委托“ElapsedEventHandler”。
1 回答

慕容森
TA貢獻(xiàn)1853條經(jīng)驗(yàn) 獲得超18個(gè)贊
像這樣在 mysql() 上設(shè)置參數(shù)
static void mysql(object sender, ElapsedEventArgs e)
我希望這個(gè)對你有用 :)
++ 通過評論添加
此代碼將允許計(jì)時(shí)器以間隔工作
在 Start() 中添加此代碼
this.timer1.Interval = 1000; this.timer1.Tick += new System.EventHandler(this.mysql_tick);
并從 Start() 中添加此代碼
private void mysql_tick( object sender, EventArgs e ){blah blah... }
++ 之后你需要使用 timer1.Start(); 使用 mysql_tick
++ timer1.Stop(); 將停止工作。
- 1 回答
- 0 關(guān)注
- 413 瀏覽
添加回答
舉報(bào)
0/150
提交
取消