G
Guest
Hi all,
I try to create a service witch handle the session switch events: Lock,
unlocked etc...
I can do this with a standard executable like this (it's just an example):
//****************************************
//****************************************
public class Event
{
static WaitHandle[] listhandle = new WaitHandle[] { new
AutoResetEvent(false) };
static public void Main()
{
SessionSwitchEventHandler handler = new
SessionSwitchEventHandler(EvHandler);
SystemEvents.SessionSwitch += handler;
WaitHandle.WaitAny(listhandle);
}
static void EvHandler(object obj, SessionSwitchEventArgs args)
{
string str = args.Reason.ToString() ;
Console.WriteLine(str);
}
}
//****************************************
//****************************************
however, when i try to use the same way for my service (i replace the
Console.writeline() by a eventlog entry) , nothing is write !!
The service start and run normally but if i locked and unlock my session
nothing is write in my eventlog.
The following is a example of what i try :
//****************************************
//****************************************
public partial class Service1 : ServiceBase
{
public Service1()
{
InitializeComponent();
SessionSwitchEventHandler handler = new
SessionSwitchEventHandler(EvHandler);
}
private void EvHandler(object obj, SessionSwitchEventArgs args)
{
string str = args.Reason.ToString();
this.EventLog.WriteEntry(str, EventLogEntryType.Information);
}
protected override void OnStart(string[] args)
{
}
protected override void OnStop()
{
}
}
//****************************************
//****************************************
The session Events are not handle by this way, have you any ideas ?
I try to create a service witch handle the session switch events: Lock,
unlocked etc...
I can do this with a standard executable like this (it's just an example):
//****************************************
//****************************************
public class Event
{
static WaitHandle[] listhandle = new WaitHandle[] { new
AutoResetEvent(false) };
static public void Main()
{
SessionSwitchEventHandler handler = new
SessionSwitchEventHandler(EvHandler);
SystemEvents.SessionSwitch += handler;
WaitHandle.WaitAny(listhandle);
}
static void EvHandler(object obj, SessionSwitchEventArgs args)
{
string str = args.Reason.ToString() ;
Console.WriteLine(str);
}
}
//****************************************
//****************************************
however, when i try to use the same way for my service (i replace the
Console.writeline() by a eventlog entry) , nothing is write !!
The service start and run normally but if i locked and unlock my session
nothing is write in my eventlog.
The following is a example of what i try :
//****************************************
//****************************************
public partial class Service1 : ServiceBase
{
public Service1()
{
InitializeComponent();
SessionSwitchEventHandler handler = new
SessionSwitchEventHandler(EvHandler);
}
private void EvHandler(object obj, SessionSwitchEventArgs args)
{
string str = args.Reason.ToString();
this.EventLog.WriteEntry(str, EventLogEntryType.Information);
}
protected override void OnStart(string[] args)
{
}
protected override void OnStop()
{
}
}
//****************************************
//****************************************
The session Events are not handle by this way, have you any ideas ?