本文将详细图解,开发Windows service的过程。

功能:数据库查询数据后,经过处理,每天定时发送邮件。

一.WinForm调试

1.新建Windows service项目

C# Windows service 开发笔录

 

2.新建WinForm程序,用来Debug

C# Windows service 开发笔录

 

C# Windows service 开发笔录

 

3.在WinForm程序中写入代码

C# Windows service 开发笔录

 

4.查询

C# Windows service 开发笔录

 

5.将查询出来的数据,进行整理

C# Windows service 开发笔录

 

6.邮件发送

C# Windows service 开发笔录

 

7.主函数调用

C# Windows service 开发笔录

 

8.调试并测试

C# Windows service 开发笔录

 

9.测试成功后,将代码复制到Service1.cs(因为Windows 服务,调试很费劲,所以才先在WinForm中测试)

C# Windows service 开发笔录

 

二.服务的安装并运行

1.添加安装程序

C# Windows service 开发笔录

C# Windows service 开发笔录

2.编译项目

C# Windows service 开发笔录

3.到bin目录下,查找生成的.exe文件,并复制桌面

-把路径记下  C:\Users\Administrator\Desktop\Test.exe

C# Windows service 开发笔录

4.cmd

C# Windows service 开发笔录

C# Windows service 开发笔录

回车,显示安装成功

C# Windows service 开发笔录

5.打开服务列表

C# Windows service 开发笔录

6.选择账号

C# Windows service 开发笔录

 

到此,开发的服务安装完毕,启动该服务为启动您的程序。

 

 

 

三.布置Batch作业

-该作业,可让服务定时运行

 

 

1.创建txt文件,内容如下,保存为.bat文件

 

 

C# Windows service 开发笔录

 

2.打开服务管理器

C# Windows service 开发笔录

 

3.新建作业

C# Windows service 开发笔录

 

4.选择时间

C# Windows service 开发笔录

 

5.选择作业文件

C# Windows service 开发笔录

 

6.确认,布置完成

C# Windows service 开发笔录

 

*到此,完整的Windows 服务安装成功。

四.服务的卸载

C# Windows service 开发笔录

C# Windows service 开发笔录

 

 

 

 

相关文章:

  • 2022-01-25
  • 2022-12-23
  • 2021-08-29
  • 2021-08-24
  • 2022-12-23
  • 2021-06-04
  • 2021-12-05
  • 2022-12-23
猜你喜欢
  • 2021-12-02
  • 2021-06-12
  • 2022-12-23
  • 2021-05-26
相关资源
相似解决方案