IService

To create a Windows Service a type has to implement IService interface and need to configured in the application config file. XecMeHost.exe installs itself as service and calls from SCM (Service Control Manager) are delegated IService object at runtime. ISerivce interface exposes following methods
  1. ServiceName - This is the property that return the name of the service. Although the service is hosted by XecMeHost.exe it can have different names for different Windows Services
  2. CanPauseAndContinue - This bool property indicate whether the service can be paused and resumed
  3. OnStart - This method is invoked by the framework when SCM starts the service. This method has to return in 30 seconds else the SCM marks that service couldn't be started.
  4. OnStop - This method is invoked by the framework when the service is stopped by the SCM. This method too has to return back in 30 seconds
  5. OnPause - This method is invoked by the framework when SCM pauses the services. Note that if the CanPauseAndContinue return false, then SCM will not invoke this method
  6. OnContinue - This method is invoked by the framework when SCM send continue signal for this service. Note that if the CanPauseAndContinue return false, then SCM will not invoke this method
  7. OnShutdown - This method is invoked by the framework when SCM signals that machine is about to shoutdown.

public class MyService: IService
{
    void OnStart()
    {
        ///This method gets invoked when the service is starting
    }

    /// Although this will not apprear on the Service console. The name appears there is what you have given during installation
    string ServiceName
    {
        get { return "My Service for order monitoring"; }
    }

    void OnStop()
    {
        ///This method gets invoked when the service is stopping
    }

    void OnShutdown()
    {
        ///This method gets invoked when machine is shutting down
    }

    bool CanPauseAndContinue
    {
        get
        {
            ///return true to indicate to SCM that your service can pause and continue
            return true;
        }
    }


    void OnPause()
    {
        ///This method gets invoked when the service pausing
    }

    void OnContinue()
    {
        ///This method gets invoked when the service resuming after pause.
    }
}

Last edited Jan 29, 2013 at 9:54 PM by slolam, version 3

Comments

punitganshani Feb 24, 2013 at 8:40 AM 
Blog Post on using XecMe to host Windows Service -
http://www.codetails.com/punitganshani/xecme-windows-service-host/20130212