0
我們似乎遇到了一個問題,即使用WMI調用來獲取遠程計算機統計信息的應用程序本身沒有正確清理。WMI調用後清理
通話的一個例子是:
public static ManagementObjectCollection getVMs(string target, ManagementObjectCollection collection)
{
ConnectionOptions options = new ConnectionOptions();
options.Authentication = System.Management.AuthenticationLevel.PacketPrivacy;
ManagementScope scope = new ManagementScope(string.Format("\\\\{0}\\root\\virtualization", target), options);
ManagementObjectSearcher searcher =
new ManagementObjectSearcher(scope, new ObjectQuery("SELECT * FROM MSVM_ComputerSystem WHERE ElementName like 'TS%'"));
try
{
ManagementObjectCollection ObjCollection = searcher.Get();
collection = ObjCollection;
return collection;
}
catch (Exception e)
{
IOModule.errorWrite(e);
IOModule.debugWrite(e.ToString());
}
return null;
}
這個偉大的工程,但隨着時間的推移,我們注意到,這些遠程機器報告的方式,尚未關閉的太多打開WMI調用。
代碼裏面應該使用using
這裏?需要清理Management
的哪一部分?它是ManagementScope
ManagementObjectSearcher
或ManagementObjectCollection
?