In the current project, I have to develop some windows services to sending out notification mails. The first challenge I faced is I can't directly run and debug the Windows service. For that I need to install the service (using installutil –I ServiceName) and attach the process to Visual studio, and then only I can debug it. It works fine for me. Then the next challenge was, debugging the code in the onStart event. Because once the service started, then only we can able to attach it to Visual Studio. So I put some code to write to text file, and/or event log. But I feel like it's not a good method. After searching in the net I got a nice workaround.
protected override void OnStart(string[] args)
{
System.Diagnostics.Debugger.Launch();
//Rest of the code
}
While starting the Service, it will display a dialog like this
After selecting Yes, Visual Studio will open up and you can start debugging. You can get more information from these links
No comments:
Post a Comment