ServiceBase.CanHandleSessionChangeEvent : ServiceBase « System.ServiceProcess « C# / C Sharp by API






ServiceBase.CanHandleSessionChangeEvent

   

using System;
using System.Timers;
using System.ServiceProcess;

class MyService : ServiceBase
{
    public MyService()
    {
        ServiceName = "My Service";
        
        AutoLog = true;
        
        CanStop = true;
        CanPauseAndContinue = true;
        CanHandleSessionChangeEvent = true;
    }

    protected override void OnStart(string[] args)
    {
        EventLog.WriteEntry("MyService Service starting. ");

    }

    protected override void OnStop()
    {
        EventLog.WriteEntry("MyService Service stopping...");
    }

    protected override void OnPause()
    {
        EventLog.WriteEntry("MyService Service pausing...");
    }

    protected override void OnContinue()
    {
        EventLog.WriteEntry("MyService Service resuming...");
    }

    protected override void OnSessionChange(SessionChangeDescription change)
    {
        EventLog.WriteEntry("MyService Session change..." +
            change.Reason);
    }

    public static void Main()
    {
        ServiceBase.Run(new MyService());
    }
}

   
    
    
  








Related examples in the same category

1.extends ServiceBase
2.ServiceBase.Run