Registering for Policy Refresh Notification in c#

F

Fred

Hello,

I've a question about implementing a group policy notification in c#. I've
read the MSDN about this and they have a sample in C++.
http://msdn.microsoft.com/library/d...gistering_for_policy_refresh_notification.asp
(Sorry for the wrap!)
I can create the events for the machine and user with the CreateEvent API
en register them with the RegisterGPNotification API. But when want to do
that in a thread created in c# and call there the WaitForSingleObject API
then i've got a problem that the thread won't stop without a call to
gpupdate. According to the MSDN doc is that correct:
<qoute>
If a thread makes an unmanaged call into the operating system that has
blocked the thread in unmanaged code, the runtime will not take control of
it for Thread.Interrupt or Thread.Abort. In the case of Thread.Abort, the
runtime marks the thread for Abort and takes control of it when it re-enters
managed code.
</qoute>
So my question is, is there a work around or a better solution for
implementing a Policy Refresh Notification?

TIA

Fred
 
C

Chris Jobson

Fred said:
Hello,

I've a question about implementing a group policy notification in c#. I've
read the MSDN about this and they have a sample in C++.
http://msdn.microsoft.com/library/d...gistering_for_policy_refresh_notification.asp
(Sorry for the wrap!)
I can create the events for the machine and user with the CreateEvent API
en register them with the RegisterGPNotification API. But when want to do
that in a thread created in c# and call there the WaitForSingleObject API
then i've got a problem that the thread won't stop without a call to
gpupdate. According to the MSDN doc is that correct:
<qoute>
If a thread makes an unmanaged call into the operating system that has
blocked the thread in unmanaged code, the runtime will not take control of
it for Thread.Interrupt or Thread.Abort. In the case of Thread.Abort, the
runtime marks the thread for Abort and takes control of it when it
re-enters managed code.
</qoute>
So my question is, is there a work around or a better solution for
implementing a Policy Refresh Notification?

How about creating a second event and use WaitForMultipleObjects to make the
thread wait on either event being signalled? When you want to interrupt or
abort the thread just signal the second event. The thread will know which
event was signalled by the return value from WaitForMultipleObjects.

Chris Jobson
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top