国产精品久久国产精麻豆99网站,激烈18禁高潮视频免费,老师含紧一点h边做边走视频动漫,双乳被一左一右的吸着

使用C#創(chuàng)建Windows服務(wù)(使用carplay)

一、開發(fā)環(huán)境

操作系統(tǒng):Windows 10 X64

開發(fā)環(huán)境:VS2015

編程語言:C#

.NET版本:.NET Framework 4.0

目標(biāo)平臺(tái):X86

二、創(chuàng)建Windows Service

1、新建一個(gè)Windows Service,并將項(xiàng)目名稱改為“MyWindowsService”,如下圖所示:

使用C#創(chuàng)建Windows服務(wù)(使用carplay)

2、在解決方案資源管理器內(nèi)將Service1.cs改為MyService1.cs后并點(diǎn)擊“查看代碼”圖標(biāo)按鈕進(jìn)入代碼編輯器界面,如下圖所示:

使用C#創(chuàng)建Windows服務(wù)(使用carplay)

3、在代碼編輯器內(nèi)輸入以下代碼,如下所示:

使用C#創(chuàng)建Windows服務(wù)(使用carplay)

using System;using System.ServiceProcess;using System.IO;namespace MyWindowsService{ public partial class MyService : ServiceBase { public MyService() { InitializeComponent(); } string filePath = @"D:MyServiceLog.txt"; protected overrIDE void OnStart(string[] args) { using (FileStream stream = new FileStream(filePath,FileMode.Append)) using (StreamWriter writer = new StreamWriter(stream)) { writer.WriteLine($"{DateTime.Now},服務(wù)啟動(dòng)!"); } } protected override void OnStop() { using (FileStream stream = new FileStream(filePath, FileMode.Append)) using (StreamWriter writer = new StreamWriter(stream)) { writer.WriteLine($"{DateTime.Now},服務(wù)停止!"); } } }}

使用C#創(chuàng)建Windows服務(wù)(使用carplay)

4、雙擊項(xiàng)目“MyWindowsService”進(jìn)入“MyService”設(shè)計(jì)界面,在空白位置右擊鼠標(biāo)彈出上下文菜單,選中“添加安裝程序”,如下圖所示:

使用C#創(chuàng)建Windows服務(wù)(使用carplay)

5、此時(shí)軟件會(huì)生成兩個(gè)組件,分別為“serviceInstaller1”及“serviceProcessInstaller1”,如下圖所示:

使用C#創(chuàng)建Windows服務(wù)(使用carplay)

6、點(diǎn)擊“serviceInstaller1”,在“屬性”窗體將ServiceName改為MyService,Description改為我的服務(wù),StartType保持為Manual,如下圖所示:

使用C#創(chuàng)建Windows服務(wù)(使用carplay)使用C#創(chuàng)建Windows服務(wù)(使用carplay)使用C#創(chuàng)建Windows服務(wù)(使用carplay)

7、點(diǎn)擊“serviceProcessInstaller1”,在“屬性”窗體將Account改為LocalSystem(服務(wù)屬性系統(tǒng)級(jí)別),如下圖所示:

使用C#創(chuàng)建Windows服務(wù)(使用carplay)

8、鼠標(biāo)右鍵點(diǎn)擊項(xiàng)目“MyWindowsService”,在彈出的上下文菜單中選擇“生成”按鈕,如下圖所示:

使用C#創(chuàng)建Windows服務(wù)(使用carplay)

9、至此,Windows服務(wù)已經(jīng)創(chuàng)建完畢。

三、創(chuàng)建安裝、啟動(dòng)、停止、卸載服務(wù)的Windows窗體

1、在同一個(gè)解決方案里新建一個(gè)Windows Form項(xiàng)目,并命名為WindowsServiceClient,如下圖所示:

使用C#創(chuàng)建Windows服務(wù)(使用carplay)

2、將該項(xiàng)目設(shè)置為啟動(dòng)項(xiàng)目,并在窗體內(nèi)添加四個(gè)按鈕,分別為安裝服務(wù)、啟動(dòng)服務(wù)、停止服務(wù)及卸載服務(wù),如下圖所示:

使用C#創(chuàng)建Windows服務(wù)(使用carplay)

3、按下F7進(jìn)入代碼編輯界面,引用“System.ServiceProcess”及“System.Configuration.Install”,并輸入如下代碼:

使用C#創(chuàng)建Windows服務(wù)(使用carplay)

using System;using System.Collections;using System.Windows.Forms;using System.ServiceProcess;using System.Configuration.Install;namespace WindowsServiceClient{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } string serviceFilePath = $"{Application.StartupPath}MyWindowsService.exe"; string serviceName = "MyService"; //事件:安裝服務(wù) private void button1_Click(object sender, EventArgs e) { if (this.IsServiceExisted(serviceName)) this.UninstallService(serviceName); this.InstallService(serviceFilePath); } //事件:啟動(dòng)服務(wù) private void button2_Click(object sender, EventArgs e) { if (this.IsServiceExisted(serviceName)) this.ServiceStart(serviceName); } //事件:停止服務(wù) private void button4_Click(object sender, EventArgs e) { if (this.IsServiceExisted(serviceName)) this.ServiceStop(serviceName); } //事件:卸載服務(wù) private void button3_Click(object sender, EventArgs e) { if (this.IsServiceExisted(serviceName)) { this.ServiceStop(serviceName); this.UninstallService(serviceFilePath); } } //判斷服務(wù)是否存在 private bool IsServiceExisted(string serviceName) { ServiceController[] services = ServiceController.GetServices(); foreach (ServiceController sc in services) { if (sc.ServiceName.ToLower() == serviceName.ToLower()) { return true; } } return false; } //安裝服務(wù) private void InstallService(string serviceFilePath) { using (AssemblyInstaller installer = new AssemblyInstaller()) { installer.UseNewContext = true; installer.Path = serviceFilePath; IDictionary savedState = new Hashtable(); installer.Install(savedState); installer.Commit(savedState); } } //卸載服務(wù) private void UninstallService(string serviceFilePath) { using (AssemblyInstaller installer = new AssemblyInstaller()) { installer.UseNewContext = true; installer.Path = serviceFilePath; installer.Uninstall(null); } } //啟動(dòng)服務(wù) private void ServiceStart(string serviceName) { using (ServiceController control = new ServiceController(serviceName)) { if (control.Status == ServiceControllerStatus.Stopped) { control.Start(); } } } //停止服務(wù) private void ServiceStop(string serviceName) { using (ServiceController control = new ServiceController(serviceName)) { if (control.Status == ServiceControllerStatus.Running) { control.Stop(); } } } }}

使用C#創(chuàng)建Windows服務(wù)(使用carplay)

4、為了后續(xù)調(diào)試服務(wù)及安裝卸載服務(wù)的需要,將已生成的MyWindowsService.exe引用到本W(wǎng)indows窗體,如下圖所示:

使用C#創(chuàng)建Windows服務(wù)(使用carplay)

5、由于需要安裝服務(wù),故需要使用UACAdministrator的權(quán)限,鼠標(biāo)右擊項(xiàng)目“WindowsServiceClient”,在彈出的上下文菜單中選擇“添加”->“新建項(xiàng)”,在彈出的選擇窗體中選擇“應(yīng)用程序清單文件”并單擊確定,如下圖所示:

使用C#創(chuàng)建Windows服務(wù)(使用carplay)

6、打開該文件,并將<requestedExecutionLevel level="asInvoker" uiAccess="false" />改為<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />,如下圖所示:

使用C#創(chuàng)建Windows服務(wù)(使用carplay)

7、IDE啟動(dòng)后,將會(huì)彈出如下所示的窗體(有的系統(tǒng)因UAC配置有可能不顯示),需要用管理員權(quán)限打開:

使用C#創(chuàng)建Windows服務(wù)(使用carplay)

8、重新打開后,在IDE運(yùn)行WindowsServiceClient項(xiàng)目;

9、使用WIN R的方式打開運(yùn)行窗體,并在窗體內(nèi)輸入services.msc后打開服務(wù),如下圖所示:

使用C#創(chuàng)建Windows服務(wù)(使用carplay)

10、點(diǎn)擊窗體內(nèi)的“安裝服務(wù)”按鈕,將會(huì)在服務(wù)中出現(xiàn)MyService,如下圖所示:

使用C#創(chuàng)建Windows服務(wù)(使用carplay)

11、點(diǎn)擊“運(yùn)行服務(wù)”按鈕,將啟動(dòng)并運(yùn)行服務(wù),如下所示:

使用C#創(chuàng)建Windows服務(wù)(使用carplay)

12、點(diǎn)擊“停止服務(wù)”按鈕,將會(huì)停止運(yùn)行服務(wù),如下圖所示:

使用C#創(chuàng)建Windows服務(wù)(使用carplay)

13、點(diǎn)擊“卸載服務(wù)”按鈕,將會(huì)從服務(wù)中刪除MyService服務(wù)。

14、以上啟動(dòng)及停止服務(wù)將會(huì)寫入D:MyServiceLog.txt,內(nèi)容如下所示:

使用C#創(chuàng)建Windows服務(wù)(使用carplay)

源代碼下載:

http://pan.baidu.com/s/1kVza3Bp

補(bǔ)充:如何調(diào)試服務(wù)

1、要調(diào)試服務(wù),其實(shí)很簡單,如需將服務(wù)附加進(jìn)程到需要調(diào)試的項(xiàng)目里面即可,假如要調(diào)試剛才建的服務(wù),現(xiàn)在OnStop事件里設(shè)置斷點(diǎn),如下所示:

使用C#創(chuàng)建Windows服務(wù)(使用carplay)

2、啟動(dòng)“WindowsServiceClient”項(xiàng)目,在“調(diào)試”菜單中選擇“附件到進(jìn)程”(服務(wù)必須事先安裝),如下所示:

使用C#創(chuàng)建Windows服務(wù)(使用carplay)

3、找到“MyWindowsService.exe”,點(diǎn)擊“附加”按鈕,如下圖所示:

使用C#創(chuàng)建Windows服務(wù)(使用carplay)

4、點(diǎn)擊“停止服務(wù)”按鈕,程序?qū)?huì)在設(shè)置斷點(diǎn)的地方中斷,如下圖所示:

使用C#創(chuàng)建Windows服務(wù)(使用carplay)

版權(quán)聲明:本文內(nèi)容由互聯(lián)網(wǎng)用戶自發(fā)貢獻(xiàn),該文觀點(diǎn)僅代表作者本人。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如發(fā)現(xiàn)本站有涉嫌抄襲侵權(quán)/違法違規(guī)的內(nèi)容, 請(qǐng)發(fā)送郵件至 舉報(bào),一經(jīng)查實(shí),本站將立刻刪除。

你是我的女人6免费观看| 国产精品国产三级国产专区53| 韩国日本欧美大尺寸suv| 揉捏奶头呻吟公交车少妇| 久久99国产精品久久99蜜桃 | 肉yin荡np公厕肉便调教| 国产96在线 | 亚洲| 日本少妇做爰全过| 中国china露脸自拍性hd| 狠狠躁18三区二区一区| 欧美精品精品一区在线发布 | 亚洲va欧美va天堂v国产综合| 影音先锋人妻啪啪av资源网站| 97超碰国产精品无码分类| 色婷婷综合久久久久中文| 亚洲一区二区三区影院| 狠狠色婷婷久久综合频道日韩| 一区二区狠狠色丁香久久婷婷| 久久精品国产精品国产精品污| 偷看农村妇女牲交| 一女多夫好涨四根高h| 夫妻那些事全集免费观看电视剧| gogo全球专业高清摄影| 日韩精品无码人成视频手机| 国产a级毛片久久久精品毛片 | 宝贝乖女你的奶真大水真多小芳| 樱花草视频www| 中文乱码人妻系列一区二区| 欧美黑人巨大精品videos| 99热在线观看| 久久99国产精品久久| 久久www香蕉免费人成| 久久精品国产亚洲av麻豆不片| 国产精品久久毛片| 国产免费又色又爽粗视频| 国产精品人妻久久久久 | 国产无遮挡裸体免费视频| 亚洲成av人片在线观看www| 少妇大叫太大太粗太爽了a片| 再灬再灬再灬深一点舒服| 国产精品日本一区二区在线播放|