C# 建立WinDows 服務windows
- Ctrl+Shift+N 新建項目,建立windows 服務
- 打開"工具箱"---右鍵---"選擇項"---找到Timer控件,看好了,這個Timer控件的是system.Timer下的.可不是System.Windows.Form.而後添加.
- 雙擊Timer控件...寫事件...
- 添加Log4Net引用 log4Net.dll
- 添加 「應用程序配置文件」,App.Config ,配置該文件
- 配置如下文件,添加Log4Net
![](http://static.javashuo.com/static/loading.gif)
[assembly: log4net.Config.XmlConfigurator()]工具
7..net
log4net.ILog log = log4net.LogManager.GetLogger("winVerifyServer");設計
string runTime = new AppSettingsReader().GetValue("RunTime", typeof(string)) as string;3d
- 在Server.cs設計界面,右擊——「添加安裝程序」
- 選中下圖第一個控件,點擊F4,右邊切換到屬性視圖;更改屬性視圖中的Account屬性爲LocalService(本地服務)
![](http://static.javashuo.com/static/loading.gif)
- 選中上面第二個控件,點擊F4,右邊切換到屬性視圖。更改ServiceName爲你本身喜歡的服務名稱,記住不要和系統的衝突了哦~,親!StartType默認爲手動,你能夠更改成自動
(Automatic)或禁用(Disabled)orm
![](http://static.javashuo.com/static/loading.gif)
- 編譯項目,而後win+R輸入cmd進入命令窗口。去對應.net版本下的目錄中找到InstallUtil.exe,我項目採用的是 .net 2.0,故路徑爲C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
![](http://static.javashuo.com/static/loading.gif)
11.最終結果:blog
![](http://static.javashuo.com/static/loading.gif)