如何在C#中运行Windows服务应用程序 [英] How to run windows service application in C#

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

问题描述

我开发了一个Windows服务应用程序,它在调试模式下有效运行,但在计算机上安装后,它不会执行计时器中的代码。



< b>我尝试了什么:



这是计时器中的代码。 Tick事件:



var myProgram = Process.GetProcessByName(notepad);

if(myProgram.Length == 0)

{

流程。启动(notepad.exe);

}

I have developed a windows service application which runs effectly on debug mode but after installing it on the computer it will not execute the codes in the timer.

What I have tried:

This is the code in the timer. Tick event:

var myProgram=Process.GetProcessByName("notepad");
if(myProgram.Length==0)
{
Process. Start("notepad.exe");
}

推荐答案

Windows服务没有UI并且正常运行系统帐户,因此您无法启动其他需要UI的应用程序,如记事本等。



重新考虑您想要做什么并使用限制。
Windows services don't have a UI and run (normally) on a system account, so you can't start other applications that require UI like notepad etc.

Rethink what you want to do and work with the restrictions.


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

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