MSDN - ManagementEventWatcher.WaitForNextEvent Method ()
大家好,
我正在使用WMI事件__InstanceOperationEvent监视设备。链接中的示例代码适用于Windows 10英文或简体中文,但不适用于法语。
根本原因是WaitForNextEvent
返回null,以使我的程序崩溃。
有解决这个问题的主意吗?谢谢!
以下是我实施的方法:
static int Main(string[] args)
{
ManagementScope scope = new ManagementScope("root\\CIMV2", options);
scope.Options.EnablePrivileges = true;
WqlEventQuery query =
new WqlEventQuery("__InstanceOperationEvent",
new TimeSpan(0, 0, 1),
"TargetInstance isa \"Win32_NetworkAdapter\"");
ManagementEventWatcher watcher =
new ManagementEventWatcher();
watcher.Query = query;
watcher.Options.Timeout = new TimeSpan(0, 0, 5);
ManagementBaseObject e = watcher.WaitForNextEvent(); // return null to e under French OS
//Cancel the subscription
watcher.Stop();
return 0;
}