IO.Directory.Exists and UNC
Hi,
have a problem when running this :
VB Code:
If IO.Directory.Exists("\\192.168.132.151\common\test\") Then
When the ip does not exist on my network the test takes forever and halts my application for 60secs.
I want my application to continue quicker than that.
anyone have any suggestions on how to get around this ?
peet
Re: IO.Directory.Exists and UNC
Thanks sevenhalo :)
I'll give it a go.
peet
Re: IO.Directory.Exists and UNC
Ummm. Did sevenhalo just delete his post? I just saw it here. Weird.
Re: IO.Directory.Exists and UNC
I did :)
I made a mistake, the DNS will resolve it even if it's not an assigned number. My array length validation will always return 1 or more, it'll just take longer if it's not assigned.
I'm looking into this a little further :)
Re: IO.Directory.Exists and UNC
oh :)
in that case dont mind my private message :)
peet
Re: IO.Directory.Exists and UNC
Quote:
Originally Posted by sevenhalo
I did :)
I made a mistake, the DNS will resolve it even if it's not an assigned number. My array length validation will always return 1 or more, it'll just take longer if it's not assigned.
I'm looking into this a little further :)
:eek: I'm glad you caught it. I was about to post almost the same thing.
Re: IO.Directory.Exists and UNC
This seems ok...
VB Code:
Private Function IsRealIP(ByVal strIn As String) As Boolean
'PRE: strIN is an ip in string format
Dim tcp As New System.Net.Sockets.TcpClient
Try
tcp.Connect(System.Net.Dns.GetHostByAddress(System.Net.IPAddress.Parse(strIn)).HostName, 80)
tcp.Close()
Return True
Catch ex As Exception
Return False
End Try
End Function
If this is .Net 05, I'm sure there's some really cool way of doing it, but as far as 1.1 and 03 goes... This is the best I could come up with.
Re: IO.Directory.Exists and UNC
Thanks for taking the time :)
Its .net 03, we wont be going for 05 for quite a while yet. Need our 3.rd party components to be 100% before we take the step into the world of fast sexy gui :D
peet
Re: IO.Directory.Exists and UNC
VB Code:
If IsRealIP("192.168.132.151") Then
If IO.Directory.Exists("\\192.168.132.151\felles\TMUNA") Then
Dim sr As New IO.StreamWriter("\\192.168.132.151\felles\TMUNA\TmMv2Version.txt")
sr.WriteLine(Application.ProductVersion)
sr.Close()
Else
Debug.WriteLine("Can not write version number to 192.168.132.151!")
End If
End If
wow went from 60 to 6 secs. :)
i can live with that :)
thanks again.
peet