VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > 编程开发 > .net教程 >
  • ASP.net教程之构建简单Windows Service示例

 
  1. 示例源码:WindowsServiceSample
  2. ServiceHelper源码:ServiceHelper

1. 创建Windows Service项目,如图:#

2. 配置服务参数#

3. 安装,启动,停止,卸载服务#

实现代码:


	
Copy
private string ServicePath => txtServicePath.Text.Trim(); private string ServiceName => "ServiceSample"; private void BtnStart_Click(object sender, EventArgs e) { if (!ServiceHelper.IsExisted(ServiceName)) { MessageBoxHelper.ShowError($"{ServiceName}不存在"); return; } ServiceHelper.Start(ServiceName); } private void BtnStop_Click(object sender, EventArgs e) { if (!ServiceHelper.IsExisted(ServiceName)) { MessageBoxHelper.ShowError($"{ServiceName}不存在"); return; } ServiceHelper.Stop(ServiceName); } private void BtnInstall_Click(object sender, EventArgs e) { if (ServiceHelper.IsExisted(ServiceName)) { MessageBoxHelper.ShowError($"{ServiceName}已经存在"); return; } ServiceHelper.Install(ServicePath); } private void BtnUnInstall_Click(object sender, EventArgs e) { if (!ServiceHelper.IsExisted(ServiceName)) { MessageBoxHelper.ShowError($"{ServiceName}不存在"); return; } ServiceHelper.Uninstall(ServicePath); } }

作者:YanZhiwei

出处:https://www.cnblogs.com/MeetYan/p/10897299.html


相关教程