473,218 Members | 1,392 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,218 software developers and data experts.

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 2374
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
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
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
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
by: Chris Wagner | last post by:
Anyone knows how to install/unistall service with VB.NET without using InstallUtil program? Thanks
2
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
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
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
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
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
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.