D
Dilip
Hi
I am using the following WMI code to watch for the termination of a
particular process. This code is running under Windows Vista.
public void WaitForDeath()
{
using (AutoResetEvent thisEvent = WatchForProcessDeath())
{
WaitHandle.WaitOne(thisEvent);
}
}
private AutoResetEvent WatchForProcessDeath()
{
AutoResetEvent evt = new AutoResetEvent(false);
string newQry =
"select * from __InstanceDeletionEvent within 2 where
TargetInstance ISA 'Win32_Process' and " +
"TargetInstance.Name = 'MyProcess.exe'";
ManagementEventWatcher mew = new ManagementEventWatcher(@"\\.\root
\CIMV2", newQry);
mew.EventArrived += delegate { evt.Set(); };
mew.Start();
return evt;
}
Our QA folks tested this functionality by calling WaitForDeath()
repeatedly in a tight loop. at some point, say after 3 hours or so,
we started getting a "Quota violation" exception of type
System.ManagementException on the Start() method of
ManagementEventWatcher.
I happened upon some posts related to this on the WMI newsgroup but I
am not clear how to solve this in my case.
1) Is this happening because of the query itself? If so, why does it
happen only after 3 hours and not right away?
2) Is this happening because I am not properly disposing of the
ManagementEventWatcher objects? In the EventArrived event I could
add:
mew.Stop();
mew.Dispose();
in addition to setting the autoreset event. I just don't know enough
about WMI to decide if it would help.
Can anyone help? (From past experience I really hope Mr. Willy
Denoyette sees this!)
I am using the following WMI code to watch for the termination of a
particular process. This code is running under Windows Vista.
public void WaitForDeath()
{
using (AutoResetEvent thisEvent = WatchForProcessDeath())
{
WaitHandle.WaitOne(thisEvent);
}
}
private AutoResetEvent WatchForProcessDeath()
{
AutoResetEvent evt = new AutoResetEvent(false);
string newQry =
"select * from __InstanceDeletionEvent within 2 where
TargetInstance ISA 'Win32_Process' and " +
"TargetInstance.Name = 'MyProcess.exe'";
ManagementEventWatcher mew = new ManagementEventWatcher(@"\\.\root
\CIMV2", newQry);
mew.EventArrived += delegate { evt.Set(); };
mew.Start();
return evt;
}
Our QA folks tested this functionality by calling WaitForDeath()
repeatedly in a tight loop. at some point, say after 3 hours or so,
we started getting a "Quota violation" exception of type
System.ManagementException on the Start() method of
ManagementEventWatcher.
I happened upon some posts related to this on the WMI newsgroup but I
am not clear how to solve this in my case.
1) Is this happening because of the query itself? If so, why does it
happen only after 3 hours and not right away?
2) Is this happening because I am not properly disposing of the
ManagementEventWatcher objects? In the EventArrived event I could
add:
mew.Stop();
mew.Dispose();
in addition to setting the autoreset event. I just don't know enough
about WMI to decide if it would help.
Can anyone help? (From past experience I really hope Mr. Willy
Denoyette sees this!)