如何为C#Windows窗体应用程序创建Windows服务 [英] How to create Windows Services for C# Windows Form Application

查看:711
本文介绍了如何为C#Windows窗体应用程序创建Windows服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows窗体上创建了一个同步程序。



请任何人告诉我创建Windows服务的过程,它将在间隔5分钟后启动程序。

解决方案
1。创建Windows服务项目

2.添加定时器组件。

3.将定时器设置为5分钟

4.在TimerTick事件停止计时器并运行程序



如果你必须重新启动程序,如果它没有启动那么

要么在程序关闭时重新启动Windows服务

或者不要停止计时器,让Windows服务在启动之前检查程序进程是否存在。


Windows服务没有UI,所以你可以'将你的WinForm应用程序作为一个运行,但是你可以:



将同步功能分解为没有UI的独立类/功能,并在服务和WinForm app。


I have created a Synchronization program on Windows Forms.

Please can any one tell me the process for creating Windows Services which will start the program after 5 minutes of Interval.

解决方案

1. Create windows service project
2. Add Timer component to it.
3. Set the timer to 5 minutes
4. In TimerTick event stop the timer and run the program

If you have to restart the program if it is not started then
either restart windows service on program close
OR don't stop the timer and let windows service check if the program process exists before starting it.


Windows Services have no UI, so you can't run your WinForm app as one, however you can:

Factor out the "sync" functionality to independent classes/functions without UI and use that in both the service and WinForm app.


这篇关于如何为C#Windows窗体应用程序创建Windows服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆