Gert Verhoeven

.NET Developer in C#, ASP.NET, DotNetNuke, ... at Ordina Belgium
posts - 5, comments - 5, trackbacks - 0

My Links

News

Archives

Post Categories

ASP.NET

General .NET

Wednesday, November 28, 2007

Debug a Windows Service without installing it

When you want to debug your own written Windows Service, you have to install the service on your local machine and attach the Visual Studio 2005 debugger to the process.

There is an easy way to start (and test) the windows service within Visual Studio 2005.

1) Add a public method to your windows service class to invoke the protected OnStart :

public void OnStart()

{

this.OnStart(null);   

}

2)  Add a new class to your windows service project

public class Entry

{

static void Main()

{

#if DEBUG

MediationService myService = new MediationService();

myService.OnStart();

System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);

#endif

}

}

3) Set the Startup object in the properties window of your project to the new Entry class

4) Set your breakpoint wherever you want and start debugging directly from Visual Studio 2005

posted @ Wednesday, November 28, 2007 3:33 PM | Feedback (1) |

Powered by: