Overwriting methods

As you have seen in the previous section, you are able to receive changes for your service state by creating an eventhandler for OnServiceStateChanged.

This event get's fired by the according named method:
  • ServiceApplication.Start changes the current state to ServiceState.Starting, followed by ServiceState.Running
  • ServiceApplication.Quit changes the current state to ServiceState.Exiting, followed by ServiceState.Exit or ServiceState.Running
  • ServiceApplication.Suspend changes the current state to ServiceState.Suspending, followed by ServiceState.Suspend
  • ServiceApplication.Resume changes the current state to ServiceState.Resuming, followed by ServiceState.Running

If there is any special need, you are able to override any these methods.

An example for overriding the Resume method could be:
public override void Resume()
    this.ServiceState = ServiceState.Resuming;
    // Your custom code here
    this.ServiceState = ServiceState.Running;

Please note: If you override any of these methods, you have to change the ServiceState manually. Otherwise you could break your Service and cause a failure in your Service.

Last edited May 31, 2008 at 10:07 AM by PeterNowak, version 4


No comments yet.