如何创建Windows服务来运行winform应用程序? [英] How to create windows service to run winform application?

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

问题描述

嗨朋友们,

i为winform应用程序编写代码,其中我使用timer定期运行表单,但我的计时器在表单或应用程序级别运行,我想在系统级别运行此计时器。 />
i发现使用windows服务我会实现相同的。那么更好的方法是通过这个,如果是的话如何在Windows服务中创建和运行应用程序。

Hi friends,
i wrote code for winform application in which i used timer to run form periodically but my timer runs on form or application level and i want to run this timer on system level.
i found that with the use of windows service i will achieve the same. so is that better way to go through this and if yes how to create and run application in windows service.

推荐答案

你不能拥有带有UI的Windows服务。以下是您的提示:如果有可能,这个UI如何在没有桌面的情况下工作?当您注销Windows时,该服务仍然有效,但没有桌面。



如果你需要在某些时间表上工作一些UI(也不是很好)想法),你可以有一个服务,在某些时刻开始你的应用程序,并且只有在可能的时候。但是这种服务已经存在,称为Windows任务计划程序: http://en.wikipedia.org/wiki/Windows_Task_Scheduler



请看我过去的回答:问题窗口服务



-SA
You cannot have the Windows service with UI. Here is the hint for you: if it was possible, how could this UI work without desktop? When you log off Windows, the service keeps working, but there is no a desktop.

If you need to work some UI on some schedule (also not a very good idea), you could have a service which starts your application at certain moments of times, and only when it is possible. But such service already exist, called Windows Task Scheduler: http://en.wikipedia.org/wiki/Windows_Task_Scheduler.

Please see my past answer: Problem a Window Services.

—SA


会员11543226写道
Member 11543226 wrote



但是先生,我怎么能在后台运行表格,这个表格与设备的文件导入导出类型进程有关,我必须每天在系统启动时运行这个应用程序。


But sir so how could i run form in background this form related to file import export kinda process for the device and i would have to run this application daily when system starts.

运行某些应用程序系统启动时不是完全相同的事情:服务(具有自动启动选项)只是仅对应于系统启动和启动阶段之一的方式之一。有许多不同的方式对应不同的阶段。



请参阅我过去对此主题的回答:

如何在用户登录系统之前启动应用程序

自动启动我的c#应用程序当我启动计算机时

启动应用程序



-SA

Running some application "when system starts" is not exactly the same thing: a service (with auto-start option) is just one of the ways corresponding only to one of the system boot and startup phases. There is a number of different ways corresponding to different phases.

Please see my past answers on this topic:
How to start the application before user login to the System,
Automatically start my c# application when i start my computer,
Start Up Application.

—SA


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

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