0
我寫過一些WMI代碼,在大多數機器上運行得非常好。但是在某些機器上(幾乎所有基於SSD的mac)都會導致巨大的性能問題。它導致WMIPrvSe進程繼續擊中I/O Other。如果您運行另一個應用程序來進行同樣的觀察,那麼它會慢慢爬到軟件無法使用的地步。WMI Event Watcher性能問題
System.Management.WqlEventQuery queryIn;
System.Management.WqlEventQuery queryOut;
System.Management.ManagementScope scope = new System.Management.ManagementScope("root\\CIMV2");
scope.Options.EnablePrivileges = true;
try
{
queryIn = new System.Management.WqlEventQuery();
queryIn.EventClassName = "__InstanceCreationEvent";
queryIn.WithinInterval = new TimeSpan(0, 0, 1);
//queryIn.GroupWithinInterval = new TimeSpan(0, 0, 0);
queryIn.Condition = @"TargetInstance ISA 'Win32_DiskDrive' AND TargetInstance.InterfaceType = 'USB'";
mUSBWatcherIn = new System.Management.ManagementEventWatcher(scope, queryIn);
//adds event handler that’s is fired when the insertion event occurs
mUSBWatcherIn.EventArrived += new System.Management.EventArrivedEventHandler(USBInserted);
queryOut = new System.Management.WqlEventQuery();
queryOut.EventClassName = "__InstanceDeletionEvent";
queryOut.WithinInterval = new TimeSpan(0, 0, 1);
//queryOut.GroupWithinInterval = new TimeSpan(0, 0, 0);
queryOut.Condition = @"TargetInstance ISA 'Win32_DiskDrive' AND TargetInstance.InterfaceType = 'USB'";
mUSBWatcherOut = new System.Management.ManagementEventWatcher(scope, queryOut);
//adds event handler that’s is fired when the insertion event occurs
mUSBWatcherOut.EventArrived += new System.Management.EventArrivedEventHandler(USBRemoved);
mUSBWatcherIn.Start();//run the watcher
mUSBWatcherOut.Start();
}
catch (Exception e)
{
System.Windows.Forms.MessageBox.Show(e.Message);
StopUSBWatcher();
}
有沒有人有任何想法可以在這裏發生什麼?如果我刪除此代碼,那麼它完美的作品。在其他機器上,它完美地工作。它非常奇怪。任何想法非常感謝!