构建简单Windows Service示例
2024-09-06 12:04:15
- 示例源码:WindowsServiceSample
- ServiceHelper源码:ServiceHelper
1. 创建Windows Service项目,如图:
2. 配置服务参数
3. 安装,启动,停止,卸载服务
实现代码:
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);
}
}
最新文章
- 修改nginx配置文件解决dx2.5下载附件停止不动的问题
- Ionic的跨域问题
- jQuery.parseJSON(json) 使用方法
- Apache Spark BlinkDB
- [React] React Fundamentals: Using Refs to Access Components
- php 之 json格式
- groovy学习(一)列表
- struts ajax多级下拉菜单
- Spring源码学习相关记录
- phpstorm webstorm 常用快捷键总结
- [转]微擎MVC
- sql字符处理
- eclipse 中springboot2.0整合jsp 出现No Java compiler available for configuration options compilerClassName
- 高能天气——团队Scrum冲刺阶段-Day 6
- 论文笔记:语音情感识别(四)语音特征之声谱图,log梅尔谱,MFCC,deltas
- 第三次Scrum编码冲刺!!!
- Win10取消开机密码方法
- vue封装插件并发布到npm上
- 陆续放给大家一些拿钱买的收费的模板,今天先给一个在某销售网站上排行第一的管理端模板 Ace Responsive Admin Template
- unity3d 资源文件从MAX或者MAYA中导出的注意事项