I have c# code that uses the following
ThreadPool.QueueUserWorkItem(new WaitCallback(parseEventLogsWmi), new object[] { server } );
and I have a server that is causing the code to hang and eventually fail because the WMi query doesn't finish in a timely manner. I believe something is wrong with WMI on the server, regardless I need a way to handle this and the timeout functions of WMI are not working. I'll get a timeout error or quota error from WMI eventually.
var conOpt = new ConnectionOptions();
conOpt.Impersonation = ImpersonationLevel.Impersonate;
conOpt.EnablePrivileges = true;
var scope = new ManagementScope(String.Format(@"\\{0}\ROOT\CIMV2", server), conOpt);
SelectQuery query = new SelectQuery("Select * from Win32_NTLogEvent Where Logfile = 'System' and TimeGenerated >='" + dateTime + "'");
ManagementObjectSearcher searcher = new
ManagementObjectSearcher(scope, query);
searcher.Options.Timeout = new TimeSpan(0, 0, 30);
searcher.Options.ReturnImmediately = true;
Is there a working way to limit the results back from WMI to 1000 results or get the timeout feature to work, or get the remaing threads left in a threadpool after a time limit, and terminate the thread in the threadpool?