Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Windows Visual-Studio Dev Win7 , +
Hi,
 
I posted this question on an article just now but I don't know how many people would see it there:
Process Information and Notifications using WMI[^]
 
So anyway. Many of the concepts I am using are explained in the article but here is my problem:
 
It just so happens that I have implemented almost identical code in a testing process monitor I have written. I use the code to keep an eye on any child (and [great]*grand kids) of a test process I have started. I do this because I need to know when the entire process completes and so I can kill any child processes if the test times out.

This code works fine 99.9% of the time but I am getting some rare errors specifically on Windows 7 computers and servers.
testing the code on my own windows 7 machine often gives me most common error which is "Exception from HRESULT: 0xFFFFFFFF" but LastWin32Error is 1008:
0x000003F0
ERROR_NO_TOKEN
An attempt was made to reference a token that does not exist.
Here is the code that triggers the error:
            const string queryString = "SELECT *" +
                                       "  FROM __InstanceOperationEvent " +
                                       "WITHIN  " + pol +
                                       " WHERE TargetInstance ISA 'Win32_Process' ";
 
            MachineName = ".";
            // You could replace the dot by a machine name to watch to that machine
            const string scope = @"\\.\root\CIMV2";
 
            // create the watcher and start to listen
	        
            _watcher = new ManagementEventWatcher(scope, queryString);
	    _watcher.EventArrived += WatcherOnEventArrived;
            _watcher.Start(); // ERROR
            _watcher.WaitForNextEvent();

Is would appear that once this error occurs once then it is almost certain to happen the next several times I try, so try-catch-retry code doesn't help.
 
Any ideas what I can do to get by this or look into it further?

Thanks
A
Posted 4-Mar-13 0:42am
Edited 5-Mar-13 1:02am
v2
Comments
Jegan Thiyagesan at 5-Mar-13 7:06am
   
Hi,
I tried your source code in my x64 W7 machine, I did not see any exceptions yet. I even enabled all the exceptions but could not reproduce.
 
Regards
Jegan
Andy Lanng at 19-Mar-13 12:35pm
   
I usually have to run the code several times before I get the error myself but when this is in use it could be called many times over and over again (not from the same instance)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 329
1 Maciej Los 290
2 Sergey Alexandrovich Kryukov 230
3 Shweta N Mishra 185
4 PIEBALDconsult 149
0 OriginalGriff 7,660
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,760


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 5 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100