Debugging Window Services

0 views
Skip to first unread message

Curtis Gibeaut

unread,
May 21, 2009, 10:03:31 AM5/21/09
to madd...@googlegroups.com
Last night at ALL.NET someone asked about how do debug a windows service.  What I typically do is create a winform with a start button and a stop button.  In the Program.cs the Main method would look something like this.

static void Main(string[] args)
{
if(args.Contains("/console"))
{
Application.Run(new FormICreated());
}
else
{
ServiceBase.Run(serviceObject);
}

The Forms OnLoad Starts the code the service executes.

 protected override void OnLoad(EventArgs e)
 {
 base.OnLoad(e);

 Start();
 ShowTrayBalloon("Services have been started", ToolTipIcon.Info);
 }


The developer then just runs the executable with a /console behind it instead of starting the service.  This allows them to attach to the process with Visual Studios.

I'm not going to spell everything out here but this is the general idea of how I do it.  

Curtis Allen Gibeaut Jr.
Insomniac Development LLC
Cell: 262.384.1657
https://www.insomdev.com
Email: cgib...@insomdev.com
Reply all
Reply to author
Forward
0 new messages