在c#中处理ManagementScope.timeout [英] handling ManagementScope.timeout in c#
问题描述
大家好,
以下代码用于使用system.management.ManagementScope(C#)连接到远程(WMI)对象。
mgmtScope = new ManagementScope( \\\\ + strHostAddress + \\ + WMIConnection.dictWMINamespace [nameSpace] + ,connOptions);
string WMITimeOut = ConfigurationManager.AppSettings [ WMIConnectionTimeout跨度>];
TimeSpan wmiTimeOutts;
int value ;
if ( int .TryParse(WMITimeOut, out value ))
{
wmiTimeOutts = new TimeSpan( 0 , 0 , value );
}
else
{
wmiTimeOutts = new TimeSpan( 0 , 0 , 60 ) ;
}
mgmtScope.Options.Timeout = wmiTimeOutts;
mgmtScope.Connect();
最近我添加了超时代码(参见带下划线的部分)。现在我想在请求超时发生时执行一些操作。
不知道如何确定请求是否已超时。任何有关这方面的帮助将不胜感激。
问候
塞巴斯蒂安
< blockquote>看起来你得到了答案: http://stackoverflow.com/questions/24887018 / handling-managementscope-timeout-in-c-sharp [ ^ ]
也许try catch会起作用。
Hi Everyone,
The following code is used for connecting to a remote (WMI) Object using system.management.ManagementScope (C#).
mgmtScope = new ManagementScope("\\\\" + strHostAddress + "\\" + WMIConnection.dictWMINamespace[nameSpace] + "", connOptions);
string WMITimeOut = ConfigurationManager.AppSettings["WMIConnectionTimeout"];
TimeSpan wmiTimeOutts;
int value;
if (int.TryParse(WMITimeOut, out value))
{
wmiTimeOutts = new TimeSpan(0, 0, value);
}
else
{
wmiTimeOutts = new TimeSpan(0, 0, 60);
}
mgmtScope.Options.Timeout = wmiTimeOutts;
mgmtScope.Connect();
Recently I have added code for timeout( see the underlined part). Now I want to do some actions when a request timeout occurs.
Not sure how to find out whether the request has been timed out or not. Any help on this would be greatly appreciated.
Regards
Sebastian
Looks like you got your answer: http://stackoverflow.com/questions/24887018/handling-managementscope-timeout-in-c-sharp[^]
Perhaps a try catch will work.
这篇关于在c#中处理ManagementScope.timeout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!