Dan Thomson
2009-05-27 13:01:01 UTC
I'm coding a multi-threaded app in VB .Net 2005 that connects to WMI on many
remote systems. Some systems have issues that are causing their thread to
hang when I try to connect. Is there a way to specify that there should be a
timeout when attempting to connect so that the connection will fail and I can
move on and gracefully exit the thread?
Here is one flavor of what I've tried
Dim strScope As String = "\\ComputerName\root\cimv2"
Dim WMIOptions As New ConnectionOptions
Dim WMIScope As New ManagementScope
WMIOptions.Impersonation = ImpersonationLevel.Impersonate
WMIOptions.Timeout = New TimeSpan(0, 60, 0)
WMIScope = New ManagementScope(strScope, WMIOptions)
WMIScope.Connect()
'The code never reaches this point on some systems.
I've tried specifying WMIScope.Options.Timeout and WMIOptions.Timeout.
Neither seem to work.
Dan
remote systems. Some systems have issues that are causing their thread to
hang when I try to connect. Is there a way to specify that there should be a
timeout when attempting to connect so that the connection will fail and I can
move on and gracefully exit the thread?
Here is one flavor of what I've tried
Dim strScope As String = "\\ComputerName\root\cimv2"
Dim WMIOptions As New ConnectionOptions
Dim WMIScope As New ManagementScope
WMIOptions.Impersonation = ImpersonationLevel.Impersonate
WMIOptions.Timeout = New TimeSpan(0, 60, 0)
WMIScope = New ManagementScope(strScope, WMIOptions)
WMIScope.Connect()
'The code never reaches this point on some systems.
I've tried specifying WMIScope.Options.Timeout and WMIOptions.Timeout.
Neither seem to work.
Dan