Troubleshooting


Troubleshooting services is different from troubleshooting normal applications. This section covers troubleshooting topics such as:

  • The problems of interactive services

  • Event logging

  • Performance monitoring

The best way to start building a service is to create an assembly with the functionality you want and a test client, before the service is actually created. Here, you can do normal debugging and error handling. As soon as the application is running, you can build a service by using this assembly. Of course, there might still be problems with the service:

  • Don’t display errors in a message box from the service (except for interactive services that are running on the client system). Instead, use the event logging service to write errors to the event log. Of course, in the client application that uses the service you can display a message box to inform the user about errors.

  • The service cannot be started from within a debugger, but a debugger can be attached to the running service process. Open the solution with the source code of the service and set breakpoints. From the Visual Studio Debug menu, select Processes and attach the running process of the service.

  • The Performance Monitor can be used to monitor the activity of services. You can add your own performance objects to the service. This can add some useful information for debugging. For example, with the Quote service, you could set up an object to give the total number of quotes returned, the time it takes to initialize, and so on.

Interactive Services

If an interactive service runs with a logged-on user, it can be helpful to display message boxes to the user. If the service should run on a server that is locked inside a computer room, the service should never display a message box. When you open a message box to wait for some user input, the user input probably won’t happen for some days because nobody is looking at the server in the computer room. However. it can get even worse than that: if the service isn’t configured as an interactive service, the message box opens up on a different, hidden, window station. In this case, no one can respond to that message box, because it is hidden and the service is blocked.

Important 

Never open dialog boxes for services running on a server system. Nobody will respond to them.

In cases where you really want to interact with the user, an interactive service can be configured. Some examples of such interactive services are the Print Spooler, which displays paper-out messages to the user, and the NetMeeting Remote Desktop Sharing service.

To configure an interactive service, you must set the option “Allow service to interact with desktop” in the Services configuration tool (see Figure 22-21). This changes the type of the service by adding the SERVICE_INTERACTIVE_PROCESS flag to the type.

image from book
Figure 22-21

Event Logging

Services can report errors and other information by adding events to the event log. A service class derived from ServiceBase automatically logs events when the AutoLog property is set to true. The ServiceBase class checks this property and writes a log entry at start, stop, pause, and continue requests.

Figure 22-22 shows an example of a log entry from a service.

image from book
Figure 22-22

Tip 

You can read more about event logging and how to write custom events in Chapter 17, “Tracing Events.”




Professional C# 2005 with .NET 3.0
Professional C# 2005 with .NET 3.0
ISBN: 470124725
EAN: N/A
Year: 2007
Pages: 427

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net