473,326 Members | 2,104 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,326 software developers and data experts.

WMI and Quota violation exception

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!)

Jun 27 '08 #1
4 6283
"Dilip" <rd*****@lycos.comwrote in message
news:73**********************************@a23g2000 hsc.googlegroups.com...
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!)


You need to stop the ManagementEventWatcher when done with it. The Quota
limit for *all* events that get handled on a Completion Port thread is 1000
which equals the maximum number of CP threads per process in .NET.
Why it only happens after 3 hours depends on the frequency they called the
method, call it in a tight loop and you won't have to wait longer than a
couple of seconds I guess.
Besides, it's preferable to use the Win32_ProcessStopTrace class on Vista
and higher, this class uses ETW which is really event driven while you are
using a polling mechanism under the covers.

Willy.
Jun 27 '08 #2
On Apr 11, 4:31 pm, "Willy Denoyette [MVP]"
<willy.denoye...@telenet.bewrote:
"Dilip" <rdil...@lycos.comwrote in message

news:73**********************************@a23g2000 hsc.googlegroups.com...
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!)

You need to stop the ManagementEventWatcher when done with it. The Quota
limit for *all* events that get handled on a Completion Port thread is 1000
which equals the maximum number of CP threads per process in .NET.
Why it only happens after 3 hours depends on the frequency they called the
method, call it in a tight loop and you won't have to wait longer than a
couple of seconds I guess.
Actually, as I mentioned in my original post, this problem happened
after running this code in a tight loop for 3 hours but I guess thats
besides the point when there seems to be an obvious error in my code.
Besides, it's preferable to use the Win32_ProcessStopTrace class on Vista
and higher, this class uses ETW which is really event driven while you are
using a polling mechanism under the covers.
Thanks a ton for replying. I changed the code to call Stop() on
receiving the EventArrived event. I will have to test it on Monday.

Meanwhile, could you show me a small snippet on how to use
Win32_ProcessStopTrace class to watch for termination of a process?
You could also point me in the right direction and that'd be fine with
me.

thanks!
Jun 27 '08 #3
On Apr 11, 4:31 pm, "Willy Denoyette [MVP]"
<willy.denoye...@telenet.bewrote:
"Dilip" <rdil...@lycos.comwrote in message

news:73**********************************@a23g2000 hsc.googlegroups.com...
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!)

You need to stop the ManagementEventWatcher when done with it. The Quota
limit for *all* events that get handled on a Completion Port thread is 1000
which equals the maximum number of CP threads per process in .NET.
Why it only happens after 3 hours depends on the frequency they called the
method, call it in a tight loop and you won't have to wait longer than a
couple of seconds I guess.
Besides, it's preferable to use the Win32_ProcessStopTrace class on Vista
and higher, this class uses ETW which is really event driven while you are
using a polling mechanism under the covers.

Willy.
Ok. It looks like all I have to do is replace my original
__InstanceDeletionEvent query with:

Select * from Win32_ProcessStopTrace where ProcessName='MyProcess.exe'

Am I right?
Jun 27 '08 #4
"Dilip" <rd*****@lycos.comwrote in message
news:a3**********************************@k13g2000 hse.googlegroups.com...
On Apr 11, 4:31 pm, "Willy Denoyette [MVP]"
<willy.denoye...@telenet.bewrote:
>"Dilip" <rdil...@lycos.comwrote in message

news:73**********************************@a23g200 0hsc.googlegroups.com...
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!)

You need to stop the ManagementEventWatcher when done with it. The Quota
limit for *all* events that get handled on a Completion Port thread is
1000
which equals the maximum number of CP threads per process in .NET.
Why it only happens after 3 hours depends on the frequency they called
the
method, call it in a tight loop and you won't have to wait longer than a
couple of seconds I guess.
Besides, it's preferable to use the Win32_ProcessStopTrace class on Vista
and higher, this class uses ETW which is really event driven while you
are
using a polling mechanism under the covers.

Willy.

Ok. It looks like all I have to do is replace my original
__InstanceDeletionEvent query with:

Select * from Win32_ProcessStopTrace where ProcessName='MyProcess.exe'

Am I right?


No, "select" for a trace events, you need to select the property of interest
in the eventhandler, something like:

using(ManagementEventWatcher w = new
ManagementEventWatcher("Win32_ProcessStopTrace"))
{
w.EventArrived += ProcessStopped;
w.Start();
Console.ReadLine(); // block main thread for test purposes
w.Stop();
}
}
static void ProcessStopped(object sender, EventArrivedEventArgs e) {

if((string)e.NewEvent.Properties["processname"].Value ==
"notepad.exe")
{
Console.WriteLine("Process: {0}, Stopped with Code: {1}",
(int)(uint)e.NewEvent.Properties["ProcessId"].Value,
(int)(uint)e.NewEvent.Properties["ExitStatus"].Value);
}
}
Willy.

Jun 27 '08 #5

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

Similar topics

1
by: Nasser | last post by:
Hello, I am coding a mathematical model with VC++. When I debug the code, I face with no erroe, but during executing, I face with below error "Unhandled exception at 0x0040c275 in Tar.exe:...
1
by: William Brogden | last post by:
I am trying to use the php_java.dll and php5servlet.dll - from pecl-5.1.4-win32.zip - dated 5/04/2006 to execute php in a Tomcat5.5.9 servlet environment. Java 1.5.0 I finally got a configuration...
2
by: Abubakar | last post by:
Hi all, I'm writing an app in vc++ 2k5 (all native/unmanaged). This application does a lot of multithreading and socket programming. Its been months since I'm developing this application, at...
1
by: Lee | last post by:
Hi all, been playing with some code overriding WndProc to get information about mouse events. So far I've tried to capture when the left mouse button is pressed using the code below. Sometimes...
1
by: Kirzak pascuale | last post by:
ok I made this exercise, for a compiler design course. it is not urgent as the assignment was due 2 days ago. i got a 4 out of 10 for effort. mainly because i did not just rehash code examples from...
2
by: Hetal | last post by:
I searched online and went through the forums as well, but i could not find a way to capture the database primary key violation exception. Any help will be much appreciated. Thanks, Hetal
3
by: =?Utf-8?B?eGJsZXNzaW5n?= | last post by:
Hello, I'm trying to communicate with a TEC Controller Newport 350B using their ..dll and VB.NET. I was able to use their example code with VB6. However, I've got following error when using...
0
by: Dilip | last post by:
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...
2
by: dantz | last post by:
Hi Everyone, Currently I am having this exception: "Attempted to read or write protected memory. This is often an indication that other memory is corrupt." I am still debugging which part of...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.