PC Review


Reply
Thread Tools Rate Thread

code takes a while to return if error

 
 
Scot
Guest
Posts: n/a
 
      7th Apr 2004
I have the following code:

Dim IP, domainName As String
domainName = "yahoo.com"

Try
IP = System.Net.Dns.GetHostByName(domainName).AddressList(0).ToString()
Catch ex As Exception
IP = "Not Valid"
End Try

Console.WriteLine(IP)
System.Threading.Thread.Sleep(2000)


When it has a resolvable domain, like yahoo.com it responds back instantly
with the ip address. However, if there is a domain in there that does not
exist, like blue2343.com, it takes upwards of 5 seconds to print "Not Valid"
to the screen. Why is that? and is there a way around it?

Thanks,

Scott


 
Reply With Quote
 
 
 
 
Raymond Lewallen
Guest
Posts: n/a
 
      7th Apr 2004
Scot,

This is mostly likely due to the time it is taking for your DNS server to
attempt to resolve the DNS name to an IP address. It is not uncommon for
3-6 seconds to pass while DNS attempts to resolve an entry that does not
exist. There is no way around the time it takes for a DNS server to exhaust
its resources in an attempt to resolve hostnames to ip addresses.

HTH,

Raymond Lewallen

"Scot" <(E-Mail Removed)> wrote in message
news:c5184s$(E-Mail Removed)...
> I have the following code:
>
> Dim IP, domainName As String
> domainName = "yahoo.com"
>
> Try
> IP =

System.Net.Dns.GetHostByName(domainName).AddressList(0).ToString()
> Catch ex As Exception
> IP = "Not Valid"
> End Try
>
> Console.WriteLine(IP)
> System.Threading.Thread.Sleep(2000)
>
>
> When it has a resolvable domain, like yahoo.com it responds back instantly
> with the ip address. However, if there is a domain in there that does not
> exist, like blue2343.com, it takes upwards of 5 seconds to print "Not

Valid"
> to the screen. Why is that? and is there a way around it?
>
> Thanks,
>
> Scott
>
>



 
Reply With Quote
 
Charles Law
Guest
Posts: n/a
 
      7th Apr 2004
Hi Raymond

I have no doubt that you are correct, however, I had assumed that Scot was
referring to the time it takes to catch and throw an exception.

I have noticed that the first time an exception is thrown and caught, a .NET
application can take a significant time (several seconds) before returning
control to the catch block.

Unfortunately for Scot, I don't know why this should be, so I am watching
this thread with interest in case there is anything I can do about it as
well. It does not seem to matter whether the exception is thrown manually
either; the first time always takes several seconds.

Charles


"Raymond Lewallen" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Scot,
>
> This is mostly likely due to the time it is taking for your DNS server to
> attempt to resolve the DNS name to an IP address. It is not uncommon for
> 3-6 seconds to pass while DNS attempts to resolve an entry that does not
> exist. There is no way around the time it takes for a DNS server to

exhaust
> its resources in an attempt to resolve hostnames to ip addresses.
>
> HTH,
>
> Raymond Lewallen
>
> "Scot" <(E-Mail Removed)> wrote in message
> news:c5184s$(E-Mail Removed)...
> > I have the following code:
> >
> > Dim IP, domainName As String
> > domainName = "yahoo.com"
> >
> > Try
> > IP =

> System.Net.Dns.GetHostByName(domainName).AddressList(0).ToString()
> > Catch ex As Exception
> > IP = "Not Valid"
> > End Try
> >
> > Console.WriteLine(IP)
> > System.Threading.Thread.Sleep(2000)
> >
> >
> > When it has a resolvable domain, like yahoo.com it responds back

instantly
> > with the ip address. However, if there is a domain in there that does

not
> > exist, like blue2343.com, it takes upwards of 5 seconds to print "Not

> Valid"
> > to the screen. Why is that? and is there a way around it?
> >
> > Thanks,
> >
> > Scott
> >
> >

>
>



 
Reply With Quote
 
Raymond Lewallen
Guest
Posts: n/a
 
      7th Apr 2004
Charles, Scot,

Perhaps Scot can step through his code and tell us if the delay is coming
when he steps into the GetHostByName method, or when he steps into the
Catch. Personally, I haven't noticed any delays in .NET code when an
exception is being thrown for the first time. Maybe thats because I'm not
looking for it

Raymond Lewallen

"Charles Law" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Raymond
>
> I have no doubt that you are correct, however, I had assumed that Scot was
> referring to the time it takes to catch and throw an exception.
>
> I have noticed that the first time an exception is thrown and caught, a

..NET
> application can take a significant time (several seconds) before returning
> control to the catch block.
>
> Unfortunately for Scot, I don't know why this should be, so I am watching
> this thread with interest in case there is anything I can do about it as
> well. It does not seem to matter whether the exception is thrown manually
> either; the first time always takes several seconds.
>
> Charles
>
>
> "Raymond Lewallen" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Scot,
> >
> > This is mostly likely due to the time it is taking for your DNS server

to
> > attempt to resolve the DNS name to an IP address. It is not uncommon

for
> > 3-6 seconds to pass while DNS attempts to resolve an entry that does not
> > exist. There is no way around the time it takes for a DNS server to

> exhaust
> > its resources in an attempt to resolve hostnames to ip addresses.
> >
> > HTH,
> >
> > Raymond Lewallen
> >
> > "Scot" <(E-Mail Removed)> wrote in message
> > news:c5184s$(E-Mail Removed)...
> > > I have the following code:
> > >
> > > Dim IP, domainName As String
> > > domainName = "yahoo.com"
> > >
> > > Try
> > > IP =

> > System.Net.Dns.GetHostByName(domainName).AddressList(0).ToString()
> > > Catch ex As Exception
> > > IP = "Not Valid"
> > > End Try
> > >
> > > Console.WriteLine(IP)
> > > System.Threading.Thread.Sleep(2000)
> > >
> > >
> > > When it has a resolvable domain, like yahoo.com it responds back

> instantly
> > > with the ip address. However, if there is a domain in there that does

> not
> > > exist, like blue2343.com, it takes upwards of 5 seconds to print "Not

> > Valid"
> > > to the screen. Why is that? and is there a way around it?
> > >
> > > Thanks,
> > >
> > > Scott
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Scot
Guest
Posts: n/a
 
      7th Apr 2004
I think Charles is correct in his assumption. I understand that DNS lookups
on non-existant domains take longer, but not in the 3 to 5 second range. A
second or two would be acceptable, but even that would be long if you there
was minimal network latency.

I believe it is something in the Try..Catch segment. Anyone?
"Raymond Lewallen" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Scot,
>
> This is mostly likely due to the time it is taking for your DNS server to
> attempt to resolve the DNS name to an IP address. It is not uncommon for
> 3-6 seconds to pass while DNS attempts to resolve an entry that does not
> exist. There is no way around the time it takes for a DNS server to

exhaust
> its resources in an attempt to resolve hostnames to ip addresses.
>
> HTH,
>
> Raymond Lewallen
>
> "Scot" <(E-Mail Removed)> wrote in message
> news:c5184s$(E-Mail Removed)...
> > I have the following code:
> >
> > Dim IP, domainName As String
> > domainName = "yahoo.com"
> >
> > Try
> > IP =

> System.Net.Dns.GetHostByName(domainName).AddressList(0).ToString()
> > Catch ex As Exception
> > IP = "Not Valid"
> > End Try
> >
> > Console.WriteLine(IP)
> > System.Threading.Thread.Sleep(2000)
> >
> >
> > When it has a resolvable domain, like yahoo.com it responds back

instantly
> > with the ip address. However, if there is a domain in there that does

not
> > exist, like blue2343.com, it takes upwards of 5 seconds to print "Not

> Valid"
> > to the screen. Why is that? and is there a way around it?
> >
> > Thanks,
> >
> > Scott
> >
> >

>
>



 
Reply With Quote
 
Raymond Lewallen
Guest
Posts: n/a
 
      7th Apr 2004
Scot,

What happens when you step into the code? Does it takes this long everytime
you run the app, even if the process is not recycled? Charles is saying "I
have noticed that the first time an exception is thrown and caught, a .NET
application can take a significant time (several seconds) before returning
control to the catch block." Have you confirmed this is what is happening
by stepping into the try...catch block?

Raymond Lewallen

"Scot" <(E-Mail Removed)> wrote in message
news:c51ehf$(E-Mail Removed)...
> I think Charles is correct in his assumption. I understand that DNS

lookups
> on non-existant domains take longer, but not in the 3 to 5 second range.

A
> second or two would be acceptable, but even that would be long if you

there
> was minimal network latency.
>
> I believe it is something in the Try..Catch segment. Anyone?
> "Raymond Lewallen" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Scot,
> >
> > This is mostly likely due to the time it is taking for your DNS server

to
> > attempt to resolve the DNS name to an IP address. It is not uncommon

for
> > 3-6 seconds to pass while DNS attempts to resolve an entry that does not
> > exist. There is no way around the time it takes for a DNS server to

> exhaust
> > its resources in an attempt to resolve hostnames to ip addresses.
> >
> > HTH,
> >
> > Raymond Lewallen
> >
> > "Scot" <(E-Mail Removed)> wrote in message
> > news:c5184s$(E-Mail Removed)...
> > > I have the following code:
> > >
> > > Dim IP, domainName As String
> > > domainName = "yahoo.com"
> > >
> > > Try
> > > IP =

> > System.Net.Dns.GetHostByName(domainName).AddressList(0).ToString()
> > > Catch ex As Exception
> > > IP = "Not Valid"
> > > End Try
> > >
> > > Console.WriteLine(IP)
> > > System.Threading.Thread.Sleep(2000)
> > >
> > >
> > > When it has a resolvable domain, like yahoo.com it responds back

> instantly
> > > with the ip address. However, if there is a domain in there that does

> not
> > > exist, like blue2343.com, it takes upwards of 5 seconds to print "Not

> > Valid"
> > > to the screen. Why is that? and is there a way around it?
> > >
> > > Thanks,
> > >
> > > Scott
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Scot
Guest
Posts: n/a
 
      7th Apr 2004
I haven't tried that. Unfortunately I am not an "official" programmer, so I
more or less hack things together until they work. I wouldn't have even the
first bit of a clue as far as how to step into the try....catch block. In
fact this is the first time I have ever used one in vb.net, and it was only
because I couldn't solve the situation another way.

It takes this long everytime I run the app, but it is started from scratch
each time.
"Raymond Lewallen" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Scot,
>
> What happens when you step into the code? Does it takes this long

everytime
> you run the app, even if the process is not recycled? Charles is saying

"I
> have noticed that the first time an exception is thrown and caught, a .NET
> application can take a significant time (several seconds) before returning
> control to the catch block." Have you confirmed this is what is happening
> by stepping into the try...catch block?
>
> Raymond Lewallen
>
> "Scot" <(E-Mail Removed)> wrote in message
> news:c51ehf$(E-Mail Removed)...
> > I think Charles is correct in his assumption. I understand that DNS

> lookups
> > on non-existant domains take longer, but not in the 3 to 5 second range.

> A
> > second or two would be acceptable, but even that would be long if you

> there
> > was minimal network latency.
> >
> > I believe it is something in the Try..Catch segment. Anyone?
> > "Raymond Lewallen" <(E-Mail Removed)> wrote in

message
> > news:(E-Mail Removed)...
> > > Scot,
> > >
> > > This is mostly likely due to the time it is taking for your DNS server

> to
> > > attempt to resolve the DNS name to an IP address. It is not uncommon

> for
> > > 3-6 seconds to pass while DNS attempts to resolve an entry that does

not
> > > exist. There is no way around the time it takes for a DNS server to

> > exhaust
> > > its resources in an attempt to resolve hostnames to ip addresses.
> > >
> > > HTH,
> > >
> > > Raymond Lewallen
> > >
> > > "Scot" <(E-Mail Removed)> wrote in message
> > > news:c5184s$(E-Mail Removed)...
> > > > I have the following code:
> > > >
> > > > Dim IP, domainName As String
> > > > domainName = "yahoo.com"
> > > >
> > > > Try
> > > > IP =
> > > System.Net.Dns.GetHostByName(domainName).AddressList(0).ToString()
> > > > Catch ex As Exception
> > > > IP = "Not Valid"
> > > > End Try
> > > >
> > > > Console.WriteLine(IP)
> > > > System.Threading.Thread.Sleep(2000)
> > > >
> > > >
> > > > When it has a resolvable domain, like yahoo.com it responds back

> > instantly
> > > > with the ip address. However, if there is a domain in there that

does
> > not
> > > > exist, like blue2343.com, it takes upwards of 5 seconds to print

"Not
> > > Valid"
> > > > to the screen. Why is that? and is there a way around it?
> > > >
> > > > Thanks,
> > > >
> > > > Scott
> > > >
> > > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Raymond Lewallen
Guest
Posts: n/a
 
      7th Apr 2004
Scot, set a breakpoint on your GetHostByName line (right-click on the line
and click set breakpoint). When you run the app it will stop there, and
then hit F11 to step into the code line by line and you will see where the
hic-cup is occurring.


 
Reply With Quote
 
Scot
Guest
Posts: n/a
 
      7th Apr 2004
I set the breakpoint on that line, then hit F11.

It highlights Sub Main() in yellow with a yellow arrow to the left.
F11 again, domainName line is now in yellow
F11, Try in yello
F11, breakpoint line in yellow
F11, End Try in yellow
F11, console.writeline in yellow
F11, sleep in yellow
then End Sub ends up in yellow

Nothing seems to take the 5 seconds, even when I rapidly go through it with
F11.

"Raymond Lewallen" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Scot, set a breakpoint on your GetHostByName line (right-click on the line
> and click set breakpoint). When you run the app it will stop there, and
> then hit F11 to step into the code line by line and you will see where the
> hic-cup is occurring.
>
>



 
Reply With Quote
 
CJ Taylor
Guest
Posts: n/a
 
      7th Apr 2004

"Scot" <(E-Mail Removed)> wrote in message
news:c51iv9$(E-Mail Removed)...
> I haven't tried that. Unfortunately I am not an "official" programmer,


Ha! don't worry about being an official programmer. I've met "official" or
"professional" programmers that don't know a damn thing. =)

>so I
> more or less hack things together until they work. I wouldn't have even

the
> first bit of a clue as far as how to step into the try....catch block. In
> fact this is the first time I have ever used one in vb.net, and it was

only
> because I couldn't solve the situation another way.
>
> It takes this long everytime I run the app, but it is started from scratch
> each time.
> "Raymond Lewallen" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Scot,
> >
> > What happens when you step into the code? Does it takes this long

> everytime
> > you run the app, even if the process is not recycled? Charles is saying

> "I
> > have noticed that the first time an exception is thrown and caught, a

..NET
> > application can take a significant time (several seconds) before

returning
> > control to the catch block." Have you confirmed this is what is

happening
> > by stepping into the try...catch block?
> >
> > Raymond Lewallen
> >
> > "Scot" <(E-Mail Removed)> wrote in message
> > news:c51ehf$(E-Mail Removed)...
> > > I think Charles is correct in his assumption. I understand that DNS

> > lookups
> > > on non-existant domains take longer, but not in the 3 to 5 second

range.
> > A
> > > second or two would be acceptable, but even that would be long if you

> > there
> > > was minimal network latency.
> > >
> > > I believe it is something in the Try..Catch segment. Anyone?
> > > "Raymond Lewallen" <(E-Mail Removed)> wrote in

> message
> > > news:(E-Mail Removed)...
> > > > Scot,
> > > >
> > > > This is mostly likely due to the time it is taking for your DNS

server
> > to
> > > > attempt to resolve the DNS name to an IP address. It is not

uncommon
> > for
> > > > 3-6 seconds to pass while DNS attempts to resolve an entry that does

> not
> > > > exist. There is no way around the time it takes for a DNS server to
> > > exhaust
> > > > its resources in an attempt to resolve hostnames to ip addresses.
> > > >
> > > > HTH,
> > > >
> > > > Raymond Lewallen
> > > >
> > > > "Scot" <(E-Mail Removed)> wrote in message
> > > > news:c5184s$(E-Mail Removed)...
> > > > > I have the following code:
> > > > >
> > > > > Dim IP, domainName As String
> > > > > domainName = "yahoo.com"
> > > > >
> > > > > Try
> > > > > IP =
> > > > System.Net.Dns.GetHostByName(domainName).AddressList(0).ToString()
> > > > > Catch ex As Exception
> > > > > IP = "Not Valid"
> > > > > End Try
> > > > >
> > > > > Console.WriteLine(IP)
> > > > > System.Threading.Thread.Sleep(2000)
> > > > >
> > > > >
> > > > > When it has a resolvable domain, like yahoo.com it responds back
> > > instantly
> > > > > with the ip address. However, if there is a domain in there that

> does
> > > not
> > > > > exist, like blue2343.com, it takes upwards of 5 seconds to print

> "Not
> > > > Valid"
> > > > > to the screen. Why is that? and is there a way around it?
> > > > >
> > > > > Thanks,
> > > > >
> > > > > Scott
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SCHTASKS - Job return code instead of return code of Job creation /execution James D Smooth Microsoft Windows 2000 CMD Promt 4 17th Dec 2008 02:36 PM
Error - Not All Code Paths Return a Value OutdoorGuy Microsoft C# .NET 4 17th May 2005 03:28 PM
Userenv 1000. Windows cannot determine the user or computer name. Return value (<return error code>). Ingmar Microsoft Windows 2000 Networking 1 18th Nov 2003 05:08 PM
Userenv 1000. Windows cannot determine the user or computer name. Return value (<return error code>). Ingmar Microsoft Windows 2000 Group Policy 1 18th Nov 2003 05:08 PM
Excel return error code Gary Lam Microsoft Excel Programming 2 18th Aug 2003 06:19 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:27 AM.