Windows服务问题 [英] Windows Service Question

查看:137
本文介绍了Windows服务问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3个Windows服务的问题。




  1. 时,WS可以在后台工作吗?是否有可能做一些工作每2分钟? (如果是,我能得到一些帮助?)


  2. 如何在简单的方式安装WS? (不Installutil.exe .......)


  3. 我怎么能运行Windows服务.exe文件?




我试过这样:

 的System.Diagnostics.Process G =新工艺(); 
G.StartInfo.FileName = @D:\demo.exe
G.Start();



但它没有工作。


解决方案

  1. 是一个窗口服务,并的确在后台工作。做同样的工作,每2分钟使用system.Timer类,并把你的代码在onElapsed事件。我最近创建这种类型的服务,发现有两种类型的定时器可以使用,确保使用正确的,否则你会找不到onElapsed事件。


  2. 我还没有尝试安装不InstallUtil.exe但我有我使用的是运行作为我的主要应用程序安装的一部分.bat文件。




在运行从Windows服务的.exe你的后续问题,运行从Windows的.exe服务我用:

 进程p =新工艺(); 
p.StartInfo.WorkingDirectory = @C:\;
p.StartInfo.FileName = @C:\demo.exe
p.StartInfo.CreateNoWindow = TRUE;
p.Start();
p.WaitForExit();



记住,可执行文件将在同一级别,这意味着它无法显示任何内容的服务运行在桌面上。如果你希望看到的任何窗口打开或.exe需要任何用户输入,那么你会感到失望和.exe文件可能会无限期地等待。 (我发现这个链接启动帮助并没有也所以这个问题的外部程序 - < A HREF =http://stackoverflow.com/questions/240171/launching-a-application-exe-from-c>启动从C#应用程序(.EXE))


I have 3 Windows Service Question

  1. Is WS can work in background ? Is it possible to do some job every 2 minutes ? (if yes, can I get some help ?)

  2. How can I install WS in simple way ? (not with Installutil.exe .......)

  3. How can I run .exe file from Windows service ?

I've tried this way:

System.Diagnostics.Process G = new Process();
    G.StartInfo.FileName = @"d:\demo.exe";
    G.Start();

but it didn't work.

解决方案

  1. Yes a windows service can and does work in the background. To do the same job every 2 minutes use the system.Timer class and put your code in the onElapsed event. I've recently created this type of service and found there are two types of Timer you can use, make sure you use the correct one or you will not find the onElapsed event.

  2. I've not tried installing without the InstallUtil.exe but I do have a .bat file that I use which is run as part of my main application installation.

Your follow-up question on running an .exe from a Windows Service, to run an .exe from a Windows Service I have used:

Process p = new Process();
p.StartInfo.WorkingDirectory = @"C:\";
p.StartInfo.FileName = @"C:\demo.exe";
p.StartInfo.CreateNoWindow = true;
p.Start();
p.WaitForExit();

Remember that the executable will run at the same level as the service which means it can't display anything on the desktop. If you are expecting to see any window open or the .exe requires any user input then you will be disappointed and the .exe may wait indefinitely. (I found this link Launch external programs helped and there is also this question on SO - Launching an Application (.EXE) from C#)

这篇关于Windows服务问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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