4

I run the same code from two different locations in my application. I know it is the same code, because it is in a class and that class only has one publicly facing function. Both places call the function with the same arguments and both are running in the UI thread.

The function does a search for a particular printer by name using an asynchronous WMI query-->

            var searcher =
                new ManagementObjectSearcher(
                    "SELECT * from Win32_Printer WHERE Name LIKE '%ZDesigner GX430t'");

            // Create an observer to trigger a callback when the search is completed.
            var watcher = new ManagementOperationObserver();
            watcher.Completed += PrinterSearchCompleted;
            watcher.ObjectReady += PrinterSearchReady;

            // Look for the printer
            _printerFound = false;
            _searchCompleted = false;
            searcher.Get(watcher);

The problem I am having is that the ObjectReady event is not triggered when I run it from one location and when I run it from another, it get's triggered all the time.

Also, another problem is that this seems to be computer specific; some of the computers I run this on work just fine, others exhibit the problem I described above.

Any ideas what I should be looking for?

Matt Zappitello
  • 785
  • 2
  • 11
  • 30
  • Search for and run the MS WMI Diagnosis Utility on the 'bad' computers, and repair/rebuild any with issues. This link might also help- http://myitforum.com/cs2/blogs/jgilbert/archive/2008/01/11/how-to-check-the-wmi-repository-before-rebuilding-it.aspx – Lizz Oct 31 '12 at 07:50
  • Did you have a chance to run the utils mentioned above? – Lizz Mar 20 '13 at 06:59
  • Sorry, but I have not. I was moved to a different project and haven't had the time to do so. I am supposed to have a chance to work on that again at some point, so I will be sure to try it. I will update this when I know more. – Matt Zappitello Mar 20 '13 at 13:43

1 Answers1

0

Couple of things to try:

  • Check if WMI service is running on all the computers.
  • Restart WMI service on the computers where it is not working.

You may find this article useful.

If its a Windows 7 or Windows Server 2008 R2 server, WMI has a memory leak problem. Check this.

Mohammad Nadeem
  • 9,134
  • 14
  • 56
  • 82