473,804 Members | 3,396 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 = WatchForProcess Death())
{
WaitHandle.Wait One(thisEvent);
}
}

private AutoResetEvent WatchForProcess Death()
{
AutoResetEvent evt = new AutoResetEvent( false);
string newQry =
"select * from __InstanceDelet ionEvent within 2 where
TargetInstance ISA 'Win32_Process' and " +
"TargetInstance .Name = 'MyProcess.exe' ";
ManagementEvent Watcher mew = new ManagementEvent Watcher(@"\\.\r oot
\CIMV2", newQry);
mew.EventArrive d += 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.Manageme ntException on the Start() method of
ManagementEvent Watcher.

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
ManagementEvent Watcher 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 6347
"Dilip" <rd*****@lycos. comwrote in message
news:73******** *************** ***********@a23 g2000hsc.google groups.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 = WatchForProcess Death())
{
WaitHandle.Wait One(thisEvent);
}
}

private AutoResetEvent WatchForProcess Death()
{
AutoResetEvent evt = new AutoResetEvent( false);
string newQry =
"select * from __InstanceDelet ionEvent within 2 where
TargetInstance ISA 'Win32_Process' and " +
"TargetInstance .Name = 'MyProcess.exe' ";
ManagementEvent Watcher mew = new ManagementEvent Watcher(@"\\.\r oot
\CIMV2", newQry);
mew.EventArrive d += 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.Manageme ntException on the Start() method of
ManagementEvent Watcher.

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
ManagementEvent Watcher 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 ManagementEvent Watcher 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_ProcessSt opTrace 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.bewro te:
"Dilip" <rdil...@lycos. comwrote in message

news:73******** *************** ***********@a23 g2000hsc.google groups.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 = WatchForProcess Death())
{
WaitHandle.Wait One(thisEvent);
}
}
private AutoResetEvent WatchForProcess Death()
{
AutoResetEvent evt = new AutoResetEvent( false);
string newQry =
"select * from __InstanceDelet ionEvent within 2 where
TargetInstance ISA 'Win32_Process' and " +
"TargetInstance .Name = 'MyProcess.exe' ";
ManagementEvent Watcher mew = new ManagementEvent Watcher(@"\\.\r oot
\CIMV2", newQry);
mew.EventArrive d += 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.Manageme ntException on the Start() method of
ManagementEvent Watcher.
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
ManagementEvent Watcher 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 ManagementEvent Watcher 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_ProcessSt opTrace 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_ProcessSt opTrace 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.bewro te:
"Dilip" <rdil...@lycos. comwrote in message

news:73******** *************** ***********@a23 g2000hsc.google groups.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 = WatchForProcess Death())
{
WaitHandle.Wait One(thisEvent);
}
}
private AutoResetEvent WatchForProcess Death()
{
AutoResetEvent evt = new AutoResetEvent( false);
string newQry =
"select * from __InstanceDelet ionEvent within 2 where
TargetInstance ISA 'Win32_Process' and " +
"TargetInstance .Name = 'MyProcess.exe' ";
ManagementEvent Watcher mew = new ManagementEvent Watcher(@"\\.\r oot
\CIMV2", newQry);
mew.EventArrive d += 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.Manageme ntException on the Start() method of
ManagementEvent Watcher.
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
ManagementEvent Watcher 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 ManagementEvent Watcher 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_ProcessSt opTrace 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
__InstanceDelet ionEvent query with:

Select * from Win32_ProcessSt opTrace where ProcessName='My Process.exe'

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

news:73******* *************** ************@a2 3g2000hsc.googl egroups.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 = WatchForProcess Death())
{
WaitHandle.Wait One(thisEvent);
}
}
private AutoResetEvent WatchForProcess Death()
{
AutoResetEvent evt = new AutoResetEvent( false);
string newQry =
"select * from __InstanceDelet ionEvent within 2 where
TargetInstance ISA 'Win32_Process' and " +
"TargetInstance .Name = 'MyProcess.exe' ";
ManagementEvent Watcher mew = new ManagementEvent Watcher(@"\\.\r oot
\CIMV2", newQry);
mew.EventArrive d += 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.Manageme ntException on the Start() method of
ManagementEvent Watcher.
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
ManagementEvent Watcher 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 ManagementEvent Watcher 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_ProcessSt opTrace 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
__InstanceDelet ionEvent query with:

Select * from Win32_ProcessSt opTrace where ProcessName='My Process.exe'

Am I right?


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

using(Managemen tEventWatcher w = new
ManagementEvent Watcher("Win32_ ProcessStopTrac e"))
{
w.EventArrived += ProcessStopped;
w.Start();
Console.ReadLin e(); // block main thread for test purposes
w.Stop();
}
}
static void ProcessStopped( object sender, EventArrivedEve ntArgs e) {

if((string)e.Ne wEvent.Properti es["processnam e"].Value ==
"notepad.ex e")
{
Console.WriteLi ne("Process: {0}, Stopped with Code: {1}",
(int)(uint)e.Ne wEvent.Properti es["ProcessId"].Value,
(int)(uint)e.Ne wEvent.Properti es["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
6777
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: 0xC0000005: Access violation reading location 0x00000004". Could you tell me, how I can fix it? I have attached the code as follows:
1
3361
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 that will start executing the single php tag: <?php phpinfo(); ?> This starts an HTML page and writes lots of configuration information but does not finish the page. Java reports: # An unexpected error has been detected by HotSpot Virtual...
2
24527
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 this point a lot of it is working just fine, my app running fine, threads r being made and destroyed, memory is being dynamically allocated at God knows how many places and ,hopefully, getting deallocated as well. Its just by coincedence I happened...
1
4203
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 the clicks will register fine, and other times it'll cause an acess violation (Attempted to read or write protected memory. This is often an indication that other memory is corrupt.) So I'm wondering why this occurs and how I can prevent it from...
1
1615
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 the deitel&deitel c++ books. now i get the program to compile, but when run, it throws an access violation exception. So to summarize: the program asks the user for the filename of the source file, opens it with fopen for reading, then takes the...
2
3220
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
9349
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 VB.NET: "Access Violation Exception was unhandled. Attempted to read or write protected memory. This is often an indication that other memory is corrupt." I have no problem when send commands to my TEC Controller (using "SendAsciiA" - see below...
0
660
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 thisEvent = WatchForProcessDeath()) { WaitHandle.WaitOne(thisEvent);
2
3811
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 my code is the cause. Is there a way not to let the exception show as of the moment? When it is about (which i dont know when) to show I will restart or close the application..
0
9705
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9575
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10564
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10073
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6846
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5513
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4288
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 we have to send another system
2
3806
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2981
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.