Re: [問題] 如何自訂Window服務

看板C_Sharp作者 (阿棠)時間17年前 (2009/01/11 16:58), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串2/3 (看更多)
※ 引述《atowng (阿棠)》之銘言: : 各位先進好: : 小弟我上網搜尋一陣子,有說可以新增專案並且使用範本裡面的 : Window服務來建立專案,不過我的Visual Studio 2005是Team Suite版的, : 所以沒有這個範本可以使用,要如何自訂Window服務, : 還有要如何將寫好的程式,安裝為Window服務。 : 謝謝! //======================================================================= 不好意思,是小弟我自己搞錯了,確實有Window服務的範本。 我按照MSDN的說明,安裝與部屬了MyServier,並且啟動我的服務, 不過我的程式好像沒有被執行: public partial class MyNewService : ServiceBase { protected override void OnStart(string[] args) { // TODO: 在此加入啟動服務的程式碼。 eventLog1.WriteEntry("In OnStart"); timer1.Interval = 300000; timer1.Enabled = true; } protected override void OnStop() { // TODO: 在此加入停止服務所需執行的終止程式碼。 eventLog1.WriteEntry("In onStop."); } protected override void OnContinue() { eventLog1.WriteEntry("In OnContinue."); } private void timer1_Tick(object sender, EventArgs e) { this.timer1.Enabled = false; StreamWriter oSW = new StreamWriter("C:\\新文字文件 (2).txt", true, Encoding.Default); oSW.Write("%%%%%%%%%%%%%"); this.timer1.Enabled = true; } } 直覺上啟動服務時timer就會被啟動就會複寫資料到.txt檔 一直找不出原因,請教大家了。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 115.43.131.39

01/14 20:44, , 1F
你用 System.Timers.Timer 試看看。
01/14 20:44, 1F
文章代碼(AID): #19QRIXVP (C_Sharp)
文章代碼(AID): #19QRIXVP (C_Sharp)