473,473 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 2316

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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.