因為需要每天定時更新資料,所以決定寫成一個windos 服務。
1。在VS2008建立windows service工程
檔案---建立---項目----windows服務,名稱AdioService
2。結構如所示,雙擊service1.cs,在onstart中寫具體代碼,注意如果代碼執行需要很長時間,則需要將方法放在子線程中,否則windows服務會啟動不起來。
3。定時器Quartz的使用
4。添加安裝程式
在AdioService.cs[設計]右鍵---添加安裝程式,會出現
注意:account選擇localhost ;StartType選擇Automatic(開機自動執行)
5。安裝服務
開始-運行-cmd
cd C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
找到debug下的.exe,複製路徑(例如 C:\Documents and Settings\Administrator\案頭\Audiomonitor\d1\AudioService\bin\Debug\AudioService.exe")
安裝命令
InstallUtil "C:\Documents and Settings\Administrator\案頭\Audiomonitor\d\AudioService\bin\Debug\AudioService.exe"
卸載命令
InstallUtil /u "C:\Documents and Settings\Administrator\案頭\Audiomonitor\d1\AudioService\bin\Debug\AudioService.exe"
在控制台---管理工具-----服務----右鍵----啟動服務
6。異常情況
如果不能正常啟動服務,說明服務有錯誤。可以利用“日誌查看器”查看錯誤資訊。(調試比較麻煩)。
注意每次對服務改動的話,都必須重新安裝。
7。想要服務在遇到異常停止後自動重啟
找到 服務-----右鍵----屬性---恢複-----重新啟動服務
定時程式請關注我的一下篇!O(∩_∩)O~ (今天總算買到票了,有時間寫點東東了)