启动Windows服务时出错 [英] Error in starting windows service

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

问题描述


我想在Windows服务中执行一些代码.我已经在Winform应用程序中测试了这些代码并成功运行.但是现在当我安装Windows服务并要启动它时,会出现一条消息,告诉我我的服务已启动并且然后停止,因为它无关紧要!!?

我怎么了?
注意:我的服务中有一个System.Timers.Timer,每15分钟执行一些代码.并且我已经以管理员身份安装了Windows Service应用程序.

Hi,
I want to execute some codes in my windows service.i have tested these codes in a winform application and its worked successfully.but now when i install my windows service and i want to start it a message appears and tell me that my service starts and then stops because it has nothing to do!!!?

what is my mistake?
Note: I have a System.Timers.Timer in my service to execute some codes every 15 minutes.and i have installed my windows service application as an administrator.

推荐答案

首先,一定要避免使用计时器.使用单独的线程代替System.Threading.Thread.Sleep.这是更可靠,更直接的编程.

其次,不查看代码就很难看到您的问题.服务更难调试.使用System.Diagnostics.EventLog并登录到系统事件日志,您可以通过以下命令打开和查看该事件:

First, avoid timers by all means. Use a separate thread instead with System.Threading.Thread.Sleep. This is much more reliable and more straightforward to program.

Secondly, it''s hard to see you problem without looking at your code. Services are harder to debug. Use System.Diagnostics.EventLog and log to the system event log you can open and view via the command:

%SystemRoot%\system32\eventvwr.msc /s



请参阅 http://msdn.microsoft.com/en-us/library/system.diagnostics .eventlog.aspx [ ^ ].

另一种方法是在单独的程序集中实现大多数代码,这些程序集可在Windows Service和常规的交互式应用程序(例如控制台应用程序)中使用.但是,请记住,Windows Service是运行代码的非常不寻常的主机:许多方面看起来会有所不同.首先创建Windows服务的非常简单的框架,并确保它首先运行,然后再逐步添加一些肉".定期以两种方式(交互方式和服务方式)执行调试.

不要忘记要使用的重要标志:静态属性System.Environment.UserInteractive,请参见 http ://msdn.microsoft.com/en-us/library/system.environment.userinteractive.aspx [



See http://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog.aspx[^].

Another way is implementing most of you code in a separate assembly which you can use in you Windows Service and also in a regular interactive application, such as console application. However, remember that Windows Service is a very unusual host for running code: many aspects will look different. Create a very simple skeleton of the Windows Service first and make sure it works first, add some "meat" later step by step. Perform debug in both modes (interactive and Service) on regular basis.

Don''t forget an important flag to use: the static property System.Environment.UserInteractive, see http://msdn.microsoft.com/en-us/library/system.environment.userinteractive.aspx[^]. Very useful.

—SA


要确定问题所在,可以尝试一下.. catch block

To identify the problem, could you put try.. catch block

try
{
....
}
catch (Exception ex)
{
... ex.Message....
}


这将找出导致此服务问题的根本原因.由此,您可以解决导致服务停止的问题.我的直觉是Windows服务定义中可能几乎没有设置/配置问题.


It will catch the root cause for this service issue. From that, you can fix the problem which stops the service. My gut feeling is that there may be few setting/configuration issue in windows service definition.


朋友您好,这是同样的问题..

请查看此问题,如果对您有帮助,它将得到解决...

使用Windows服务 [
Hello friend this is same question like this..

please see this question and it will be solved if it is help full to you...

work with windows service[^]


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

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