473,626 Members | 3,388 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Handle SessionSwitchEv ent with Service

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()
{
SessionSwitchEv entHandler handler = new
SessionSwitchEv entHandler(EvHa ndler);
SystemEvents.Se ssionSwitch += handler;
WaitHandle.Wait Any(listhandle) ;
}

static void EvHandler(objec t obj, SessionSwitchEv entArgs args)
{
string str = args.Reason.ToS tring() ;
Console.WriteLi ne(str);
}
}
//*************** *************** **********
//*************** *************** **********

however, when i try to use the same way for my service (i replace the
Console.writeli ne() 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()
{
InitializeCompo nent();
SessionSwitchEv entHandler handler = new
SessionSwitchEv entHandler(EvHa ndler);
}

private void EvHandler(objec t obj, SessionSwitchEv entArgs args)
{
string str = args.Reason.ToS tring();
this.EventLog.W riteEntry(str, EventLogEntryTy pe.Information) ;
}

protected override void OnStart(string[] args)
{

}

protected override void OnStop()
{

}

}
//*************** *************** **********
//*************** *************** **********

The session Events are not handle by this way, have you any ideas ?

--
Michel
Feb 26 '07 #1
2 3366
Hi Michel,

To understand why the event is not fired in your service, we need to first
understand two concepts here:

1) The session switch event is fired when fast user switching feature is
enabled (such as on Windows XP). The event is actually a windows message
broadcasted to all top-level windows. The SystemEvents class in .NET
Framework 2.0 internally creates a hidden window to receive these broadcast
messages and fire managed events accordingly.

2) A service (see
http://pluralsight.com/wiki/default....IsADaemon.html)
normally runs in a different Window Station
(http://pluralsight.com/wiki/default....IsAWindowStati
on.html) other than the interactive Window Station "WinSta0", which is
where your logon session belongs to.

A Window Station is a securable object that is associated with a process,
and contains a clipboard, an atom table, and one or more desktop objects.

A desktop is a securable object contained within a window station. A
desktop has a logical display surface and contains user interface objects
such as windows, menus, and hooks.
(http://msdn2.microsoft.com/en-us/library/ms681928.aspx)

A broadcast message can only send to all top-level windows in the same
desktop. (http://www.flounder.com/messaging.htm)

Unless you put your service in the interactive Window Station (WinSta0) too
(http://pluralsight.com/wiki/default....oDisplayAUserI
nterfaceFromADa emon.html), your service will not be able to receive the
session switch message.
Hope this helps. Let me know if you need further information. Thanks.
Sincerely,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 27 '07 #2
Your help and documentations were very helpful.
Indeed, Now I see that I had a problem of philosohie.
I think that in the case of the development of a service it is necessary to
"thinking directly in service development and not to translate executable
developement to service.
Thank you for your assistance on the “philosophy of the service.
--
Michel
"Walter Wang [MSFT]" wrote:
Hi Michel,

To understand why the event is not fired in your service, we need to first
understand two concepts here:

1) The session switch event is fired when fast user switching feature is
enabled (such as on Windows XP). The event is actually a windows message
broadcasted to all top-level windows. The SystemEvents class in .NET
Framework 2.0 internally creates a hidden window to receive these broadcast
messages and fire managed events accordingly.

2) A service (see
http://pluralsight.com/wiki/default....IsADaemon.html)
normally runs in a different Window Station
(http://pluralsight.com/wiki/default....IsAWindowStati
on.html) other than the interactive Window Station "WinSta0", which is
where your logon session belongs to.

A Window Station is a securable object that is associated with a process,
and contains a clipboard, an atom table, and one or more desktop objects.

A desktop is a securable object contained within a window station. A
desktop has a logical display surface and contains user interface objects
such as windows, menus, and hooks.
(http://msdn2.microsoft.com/en-us/library/ms681928.aspx)

A broadcast message can only send to all top-level windows in the same
desktop. (http://www.flounder.com/messaging.htm)

Unless you put your service in the interactive Window Station (WinSta0) too
(http://pluralsight.com/wiki/default....oDisplayAUserI
nterfaceFromADa emon.html), your service will not be able to receive the
session switch message.
Hope this helps. Let me know if you need further information. Thanks.
Sincerely,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 27 '07 #3

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

Similar topics

2
7208
by: Simon Niederberger | last post by:
Hi I've written a Windows Service which has - several (0-100) listeners threads which spawn worker threads based on events, timers etc - several (0-300) worker threads which handle data (message based) and terminate after processing I'm wondering what exactly happens when I stop the service. I don't see an ThreadAbortedException, but I'm worried my worker threads might be
0
1214
by: Tiro | last post by:
Hi, I am trying to understand how does .Net Web Service handle requests for multiple clients simultaneously. Here is what I am trying to achieve. I have created a web serive that search database based on client request. Client submits query string. Issue: If I try to access web service from 2 clients simultaneously using
1
1872
by: Patrick Dugan | last post by:
Is it possible to get the handle of a running service? I have a program (ActiveX program) running in memory. When I start my service I need to pass the service's handle to that program in order to attach to it. I cannot use Me.Handle because there is no such information within a service application. I have tried this small routine:
3
1733
by: Hans Merkl | last post by:
Hi, I am helping to build a web app that's pretty much a wrapper around a web service. The question now is how to store the handle of the web service object between requests. My client is using SQL server for session state so I don't think I can store the web service handle there since it's not serializable. Opening up a connection to this particular service is quite slow so I don't want to reopen it for every request.
2
1159
by: Max | last post by:
Hi, I am helping to build a web app that's pretty much a wrapper around a web service. The question now is how to store the handle of the web service object between requests. My client is using SQL server for session state so I don't think I can store the web service handle there since it's not serializable. Opening up a connection to this particular service is quite slow so I don't want to reopen it for every request.
2
2504
by: Stuart Ferguson | last post by:
I currently have a service which is written using C++/MFC and this service calls multiple dlls. This service uses these dlls to pass messages to another service via sockets. I am about to write one of these dlls in c# however the service currently passes a handle to a socket created in the service to allow the dll to send a message. Is there a way of creating a socket in the c# dll similar to the Attach method of the CSocket class. ...
6
2043
by: Liming | last post by:
Hi, In a typical 3 tier model (view layer, busines layer and data access layer) where do you handle your exceptions? do you let it buble up all the way to the .aspx pages or do you handle it in your business layer and/or data access layer? suppose in my data access layer, I provide try and catch, log the exception and re-throw it back to business layer, then in yoru business layer, what do you do? throw it back to the code behind or...
5
1482
by: =?Utf-8?B?R3V5IENvaGVu?= | last post by:
Hi all I use vb.net 2005 Lets say I have the handle number of a progress bar from program1.exe Can I change the value of the progress bar from program2.exe using this handle number? TIA Guy Cohen
5
1667
by: Eric Kaplan | last post by:
In C++, there is datatype HANDLE void* HANDLE then HANDLE is similar to "file handle"? which is unique identifier for a file, for a process, for a thread ... etc which is returned by a function when it's creating something - like creating a thread, creating a process, creating a file ... etc
0
8268
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
1
8366
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8510
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6125
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 presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5575
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4093
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4202
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2628
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 we have to send another system
1
1812
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.