473,511 Members | 14,134 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

service unable to reject suspend query on XP

dr
I created a basic service using VS2005. Add OnPowerEvent method as detailed
on MSDN and return false to a PowerBroadcastStatus.QuerySuspend notification.
The service also has set CanHandlePowerEvent = true. But the service still
fails to reject standby. If I do the same in VS2003, it does reject standby,
anyone else done or seen this with VS2005? Even if I set the code to return
false to all PowerBroadcastStatus events, it still doesn't reject standby.
Jul 12 '06 #1
3 2392
JMS

dr schrieb:
I created a basic service using VS2005. Add OnPowerEvent method as detailed
on MSDN and return false to a PowerBroadcastStatus.QuerySuspend notification.
The service also has set CanHandlePowerEvent = true. But the service still
fails to reject standby. If I do the same in VS2003, it does reject standby,
anyone else done or seen this with VS2005? Even if I set the code to return
false to all PowerBroadcastStatus events, it still doesn't reject standby.
Actually in .NET 2.0 the OnPowerEvent is broken (in my opinion)!
Microsoft decided to a) let it run asynchronously and b) ignore the
return code. You already have seen b) and what a) means is that the
order of events can be changed (e.g. I got Suspend just before a
QuerySuspend). In MSDN groups this topic is discussed and the Microsoft
team states that in Vista/Longhorn the power event mechanismn is no
longer reliable (can't believe that) and that therefore the behaviour
in .NET has changed.

If you really need it: there is a work-around which reactivates the
..NET 1.1 behaviour.

Jochen

Aug 7 '06 #2
dr
thanks for the info. Is this work-around documented anywhere - can you send
me a link or post the info?

thanks again!

DR

"JMS" wrote:
>
dr schrieb:
I created a basic service using VS2005. Add OnPowerEvent method as detailed
on MSDN and return false to a PowerBroadcastStatus.QuerySuspend notification.
The service also has set CanHandlePowerEvent = true. But the service still
fails to reject standby. If I do the same in VS2003, it does reject standby,
anyone else done or seen this with VS2005? Even if I set the code to return
false to all PowerBroadcastStatus events, it still doesn't reject standby.

Actually in .NET 2.0 the OnPowerEvent is broken (in my opinion)!
Microsoft decided to a) let it run asynchronously and b) ignore the
return code. You already have seen b) and what a) means is that the
order of events can be changed (e.g. I got Suspend just before a
QuerySuspend). In MSDN groups this topic is discussed and the Microsoft
team states that in Vista/Longhorn the power event mechanismn is no
longer reliable (can't believe that) and that therefore the behaviour
in .NET has changed.

If you really need it: there is a work-around which reactivates the
..NET 1.1 behaviour.

Jochen

Aug 7 '06 #3
No, the Work-Around is not documented - at least as far as I know. And
actually it shouldn't work (although Keith Brown explained how evil
FullTrust code can be
http://msdn.microsoft.com/msdnmag/is...s/default.aspx
which is exactly what I use here) but it does! Before I show the code some
comments. First I hope that some Microsoft guy reads this and comments how
we should write future services which are aware of power broadcast events.
And second to explain what happens:

1. The Service classes constructor (!) finds the CommandCallbackEx
registered by the base class and replaces it by its own stub.
2. The stub forwards all requests other than the power state information
(13) to the base classes method (actually the OnShutdown no longer works
with .NET 2.0, too but I didn't need it)
3. The stub handles OnPowerEvent the way .NET 1.1 does it.

I use this code on different systems for around four months and it seems to
work fine.

Regards

Jochen

PS: The work-around is used in here (german web site only):
http://www.psimarron.net/vcrnet - the installer includes full sources but I
think the extract shown below will fit your needs.

---------------------
Work-Around Code:
---------------------
public class Service : System.ServiceProcess.ServiceBase

{

public Service()

{

// Find the initialisation routine - may break in later versions

MethodInfo init = typeof(ServiceBase).GetMethod("Initialize",
BindingFlags.NonPublic | BindingFlags.Instance);

// Call it to set up all members

init.Invoke(this, new object[] { false });

// Find the service callback handler

FieldInfo handlerEx = typeof(ServiceBase).GetField("commandCallbackEx",
BindingFlags.NonPublic | BindingFlags.Instance);

// Read the base class provided handler

m_Forward = (Delegate)handlerEx.GetValue(this);

// Create a new delegate to our handler

Delegate test = Delegate.CreateDelegate(m_Forward.GetType(), this,
"ServiceCallbackEx");

// Install our handler

handlerEx.SetValue(this, test);

// This call is required by the Windows.Forms Component Designer.

InitializeComponent();

}

private int ServiceCallbackEx(int command, int eventType, IntPtr eventData,
IntPtr eventContext)

{

// Call the base class implementation which is fine for all but power and
session management

if (13 != command) return (int)m_Forward.DynamicInvoke(command, eventType,
eventData, eventContext);

// Process and forward success code

if (OnPowerEvent((PowerBroadcastStatus)eventType)) return 0;

// Abort power operation

return 0x424d5144;

}

"dr" <dr@discussions.microsoft.comwrote in message
news:90**********************************@microsof t.com...
thanks for the info. Is this work-around documented anywhere - can you
send
me a link or post the info?

thanks again!

DR

"JMS" wrote:
>>
dr schrieb:
I created a basic service using VS2005. Add OnPowerEvent method as
detailed
on MSDN and return false to a PowerBroadcastStatus.QuerySuspend
notification.
The service also has set CanHandlePowerEvent = true. But the service
still
fails to reject standby. If I do the same in VS2003, it does reject
standby,
anyone else done or seen this with VS2005? Even if I set the code to
return
false to all PowerBroadcastStatus events, it still doesn't reject
standby.

Actually in .NET 2.0 the OnPowerEvent is broken (in my opinion)!
Microsoft decided to a) let it run asynchronously and b) ignore the
return code. You already have seen b) and what a) means is that the
order of events can be changed (e.g. I got Suspend just before a
QuerySuspend). In MSDN groups this topic is discussed and the Microsoft
team states that in Vista/Longhorn the power event mechanismn is no
longer reliable (can't believe that) and that therefore the behaviour
in .NET has changed.

If you really need it: there is a work-around which reactivates the
..NET 1.1 behaviour.

Jochen


Aug 7 '06 #4

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

Similar topics

11
2719
by: Keith Langer | last post by:
I have an application which consists of a main work thread and multiple threads which each maintain a TCP socket. When a configuration change occurs, all activity on the socket threads must be...
3
5107
by: belgiozen | last post by:
Hi, I have a working windows service,it is looking for files on the disk and when some of the files are cupdated it calls an executable. But it takes a lot of time(about 10 minutes) to run the...
7
7256
by: BW | last post by:
Hi all! I'm not sure where to post this so I'm giving these a try. If there is a better (more appropriate) place to post please let me know. I want to create a service (in C#). The service's...
3
13773
by: Chris Wagner | last post by:
Anyone knows how to install/unistall service with VB.NET without using InstallUtil program? Thanks
2
2289
by: Sakharam Phapale | last post by:
Hi All, In following example, while playing file, if thread goes in WaitSleepJoin state, due to Thread.Sleep method. Now I want to suspend thread by clicking on cmdSuspend button. I have...
6
9073
by: Siegfried Heintze | last post by:
I have the following C# code in my web service: public static extern double add_(double X, double Y ); public double add (double X, double Y){ return add_(X, Y); }
9
1486
by: TulasiKumar | last post by:
Hi all, What is my requirement is i want to get the TCPIP data from TCP Port.I had written the code in c#.Net.What i had written the code is pasted below.what i written the code is correct or...
6
1418
by: Robert Speck | last post by:
Hi there, Can anyone shed anymore light on why "Thread.Suspend()" has been deprecated by MSFT beyond what MSDN says about it. I'm not sure if I quite appreciate the various pitfalls they discuss...
3
1577
by: anandkhinvasara | last post by:
I access certain tables of SQL Server on Access front-end. I want to suspend all the activities on front - end till the job on SQL Server is over. Any ideas how I about it ? Thanks, Anand
0
7137
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...
1
7074
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...
0
7506
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
5659
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
5063
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
3219
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
1572
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 ...
1
780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
445
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.