Windows服务没有命中Onstart()方法。 [英] Windows service doesn't hit Onstart() method.

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

问题描述

我已经创建了一个Windows服务我的WCF,当我停止服务并且我运行应用程序时它没有抛出任何错误。当我调试它时,甚至点击onstart方法的Windows服务。



I have created a windows service my WCF and when i stop the the service and i run the application it is not throwing any error.When i debug it dint even hit onstart method of windows service.

protected override void OnStart(string[] args)
       {
           System.Diagnostics.Debugger.Launch();
           if (myServiceHost != null)
           {
               myServiceHost.Close();
           }
           myServiceHost = new ServiceHost(typeof(Service1));
           myServiceHost.Open();
       }





如何调试onstart()方法?



How can i debug the onstart() method?

推荐答案

显然,如果你展示了一些从未被调用过的方法(被叫,不是命中),除了这个方法之外什么都没有,你就不会显示问题所在的代码。问题总是在这种方法之外。这不是很明显吗?



此外,我不能100%肯定你的结论是从未调用过该方法。调试Windows服务并不是一件容易的事情。我甚至不确定您是否尝试正确启动服务。它不能作为常规应用程序启动。它不会像服务那样​​表现,除非它是由Service Controlled启动的,这是一个特殊的应用程序主机。



所以,你应该得到一个基本原则根据您提供的信息,这就是全部。从这一点开始,您可以开始调查。这里有一个提示:如果没有调用此方法,您甚至没有开始开发Windows服务。请参阅:

http://msdn.microsoft.com/en-us /library/y817hyb6.aspx [ ^ ],

http://msdn.microsoft.com/en -us / library / zt39148a.aspx [ ^ ]。



-SA
Apparently, if you show some method which is never called (called, not "hit"), and nothing except this method, you don't show the code where your problem is. The problem is always outside this method. Isn't this obvious?

Besides, I cannot be 100% sure that your conclusion that the method is never called. Debugging of a Windows Service is not such a trivial thing. I'm not even sure you attempted to start the Service correctly. It cannot be started as a regular application. It won't behave like a Service unless it is started by a Service Controlled, which is a special application host.

So, you should get one of the basic principles, and this is all, based on the information you provided. From this point, you can start your investigation. Here is a hint for you: if this method is not called, you did not even start developing a Windows Service. Please see:
http://msdn.microsoft.com/en-us/library/y817hyb6.aspx[^],
http://msdn.microsoft.com/en-us/library/zt39148a.aspx[^].

—SA


这篇关于Windows服务没有命中Onstart()方法。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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