WMI and Quota violation exception

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dilip

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

  • Willy Denoyette [MVP]

    #2
    Re: WMI and Quota violation exception

    "Dilip" <rdilipk@lycos. comwrote in message
    news:73af5d1f-b71f-4362-bb91-a3a74e47977a@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.


    Comment

    • Dilip

      #3
      Re: WMI and Quota violation exception

      On Apr 11, 4:31 pm, "Willy Denoyette [MVP]"
      <willy.denoye.. .@telenet.bewro te:
      "Dilip" <rdil...@lycos. comwrote in message
      >
      news:73af5d1f-b71f-4362-bb91-a3a74e47977a@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.
      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!

      Comment

      • Dilip

        #4
        Re: WMI and Quota violation exception

        On Apr 11, 4:31 pm, "Willy Denoyette [MVP]"
        <willy.denoye.. .@telenet.bewro te:
        "Dilip" <rdil...@lycos. comwrote in message
        >
        news:73af5d1f-b71f-4362-bb91-a3a74e47977a@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?

        Comment

        • Willy Denoyette [MVP]

          #5
          Re: WMI and Quota violation exception

          "Dilip" <rdilipk@lycos. comwrote in message
          news:a3bd717b-f9ba-477a-9b15-1b9f82a09974@k1 3g2000hse.googl egroups.com...
          On Apr 11, 4:31 pm, "Willy Denoyette [MVP]"
          <willy.denoye.. .@telenet.bewro te:
          >"Dilip" <rdil...@lycos. comwrote in message
          >>
          >news:73af5d1 f-b71f-4362-bb91-a3a74e47977a@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.

          Comment

          Working...