Click here to Skip to main content
13,700,737 members
Click here to Skip to main content
Add your own
alternative version


47 bookmarked
Posted 5 Jul 2006

Windows Service Test Form

, 5 Jul 2006
Rate this:
Please Sign up or sign in to vote.
An article on service debugging in VS2005.


There are a few articles on the internet on debugging Windows Services in VS 2005. The official method is to attach a debugger to the service process once it has started. This makes it difficult to step through a service's startup process. The article, Debugging Windows Services under Visual Studio .NET, by Lee Humphries shows how to isolate individual methods using the DEBUG preprocessor directive. Here, we go a step further and create a test form as a sort of "service sandbox", to allow more interaction.

The ServiceTestForm keeps its own thread going, sort of like the system service manager. The difference here is that your service may not run as a system user. EventLog may not behave as expected either. It would be wise to use the static EventLog.WriteEntry instead of your EventLog instance.

Using the code

The code uses Anthony Roach’s C# Scheduler service as an example. To apply your own service, copy the embedded class ServiceTestForm into your class, and use the Main below. The form allows you to set breakpoints anywhere, including custom commands. Remember that command IDs below 128 are reserved for system commands.

static void Main()
   #if DEBUG
         new ServiceTestForm(new ScheduleService()));
         new System.ServiceProcess.ServiceBase[] { new ScheduleService() });

Points of interest

At first, I thought it would be nice to override ServiceBase.EventLog properties in another preprocessor directive. Maybe it could redirect EventLog entries to the TextBox, but it turns out EventLog.WriteLine isn't virtual. If anybody has a better solution to this, please forumize it and Zip me an email.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

John Boero
United States United States
John Boero is a C# and graphics hobbyist. Some discoveries are too good to be kept closed, and deserve to be given back to the open community that has provided so much already.

You may also be interested in...


Comments and Discussions

GeneralMoving ServiceTestForm outside the service class Pin
Mike Lang31-Aug-07 10:41
memberMike Lang31-Aug-07 10:41 
GeneralAutomated Interface, rather than a one-off Pin
Anderson Imes22-Aug-07 13:56
memberAnderson Imes22-Aug-07 13:56 
QuestionWhy not to use ServiceController? Pin
HDV18-Jul-06 21:22
memberHDV18-Jul-06 21:22 
AnswerRe: Why not to use ServiceController? Pin
HDV18-Jul-06 22:35
memberHDV18-Jul-06 22:35 
GeneralYup... Pin
John Boero19-Jul-06 3:08
memberJohn Boero19-Jul-06 3:08 
GeneralThanks! Pin
Herman Chelette11-Jul-06 2:14
memberHerman Chelette11-Jul-06 2:14 
Generalexcellent Pin
c4tes7-Jul-06 5:02
memberc4tes7-Jul-06 5:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web04-2016 | 2.8.180910.1 | Last Updated 5 Jul 2006
Article Copyright 2006 by John Boero
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid