Search code examples
c#.neteventslogoutshutdown

SessionEndingEvent not getting called


this is my C# code:

    void main()
    {
        SystemEvents.SessionEnding += new SessionEndingEventHandler(SystemEvents_SessionEnding);
    }

    void SystemEvents_SessionEnding(object sender, SessionEndingEventArgs e)
    {
        Console.WriteLine(e.Reason);
    }

Somehow, there is no output. Any ideas why?


Solution

  • http://msdn.microsoft.com/en-us/library/microsoft.win32.systemevents.aspx (Example 2) pretty much explains everything about SystemEvents in windows services.