473,387 Members | 1,529 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Cannot get SessionEnding event in console application

Hi All,

I am trying to fetch system-events, and I am successful
with "TimeChanged", but cannot get "SessionEnding". I am
not an OO expert and so - just to be sure - I made all
my methods public and static, this this does'nt seem
to help.

Could someone plesase help? My code is below:

using System;
using Microsoft.Win32;
using System.Diagnostics;
using System.Threading;

public class SystemEventDemo
{

public static EventLog eventLog = new EventLog("Application", ".",
"AdminTools");
public static Microsoft.Win32.SessionEndingEventHandler
sessionEndingEventHandler = new
Microsoft.Win32.SessionEndingEventHandler(OnSessio nEnding);
public static EventHandler timeChanged = new EventHandler(OnTimeChanged);

[MTAThread]
public static void Main()
{
Microsoft.Win32.SystemEvents.SessionEnding += sessionEndingEventHandler;
Microsoft.Win32.SystemEvents.TimeChanged += timeChanged;
while(true)
{
Console.WriteLine("Waiting for system-events!");
Thread.Sleep(60000);
}
}

public static void OnSessionEnding(object sender,
Microsoft.Win32.SessionEndingEventArgs e)
{
// the user session is ending or computer is shutting down /////// THIS
DOES NOT WORK!
Console.WriteLine("OnSessionEnding!");
eventLog.WriteEntry
(
String.Format
(
"The 'OnSessionEnding' event occured, Reason:{0}.",
e.Reason.ToString()
),
EventLogEntryType.Information,
2
);
}

public static void OnTimeChanged(object sender, EventArgs e)
{
//The time was changed[this fires and logs as expected]
Console.WriteLine("OnTimeChanged, begin.");
eventLog.WriteEntry
(
"OnTimeChanged",
EventLogEntryType.Information,
3
);
Console.WriteLine("OnTimeChanged, end.");
}

}

Any help is welcome. I am currently out of hope and even searches in
web/group
on google does not give any useful results.

Best regards,
Manfred Braun

(Private)
Mannheim
Germany

mailto:_m*************@manfbraun.de
(Remove the anti-spam-underscore to mail me!)
Nov 16 '05 #1
0 2295

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Manfred Braun | last post by:
Hi All, I am trying to fetch system-events, and I am successful with "TimeChanged", but cannot get "SessionEnding". I am not an OO expert and so - just to be sure - I made all my methods public...
11
by: avivgur | last post by:
Hello, I have devised a console application that uses a System.Timers.Timer and its Elapsed event. The problem is that I want the program to continue to run so that each time the event is raised,...
0
by: Roshan | last post by:
Hi All, Iam using WMI for the first time and am trying to detect and stop a user login event. But when i run my code, i notice that the event handler is not getting called. Can some one tell me...
0
by: thjwong | last post by:
I'm using WinXP with Microsoft Visual C++ .NET 69462-006-3405781-18776, Microsoft Development Environment 2003 Version 7.1.3088, Microsoft .NET Framework 1.1 Version 1.1.4322 SP1 Most developers...
3
by: geskerrett | last post by:
We have been asked to develop and application for a client that is a 'notification" system. We would like to use python, but are struggling to find the right starting point. Any suggestions, tips...
5
by: bbembi_de | last post by:
Hello everyone, I'm listening to the SessionEnding event, so I can close my application properly when Windows is shutting down. I do some disposing and stuff if the event occurrs but windows...
1
by: chitra g | last post by:
Hi, I tried all the options below but did not work. Your suggestions please.
2
by: =?Utf-8?B?TmVldGE=?= | last post by:
Hi, I creating a console application. In that I want to catch the cancel event of the console application .Please guide me in this.I figured out that I will have to attach event to the...
4
by: federico | last post by:
Hello, I am trying to setup a Visual Basic "Console" application for searching Outlook folders. To this end I am trying to implement a Handler for the Outlook.Application.AdvancedSearchComplete...
6
by: cnixuser | last post by:
Hello, I have a basic application written which is designed to data over a serial cable and then receive a response back. I am not getting any triggers to my data received event. I have tried...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.