如果错误,代码需要一段时间才能返回 [英] code takes a while to return if error

查看:62
本文介绍了如果错误,代码需要一段时间才能返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:


Dim IP,domainName As String

domainName =" yahoo.com"

尝试

IP = System.Net.Dns.GetHostByName(domainName)。AddressLi st(0).ToString()

Catch ex As Exception

IP =无效

结束尝试


Console.WriteLine(IP)

系统.Threading.Thread.Sleep(2000)

如果它有一个可解析的域名,比如yahoo.com,它会立即用IP地址回复
。但是,如果其中存在不存在
的域名,例如blue2343.com,则需要花费5秒钟才能打印无效

到屏幕。这是为什么?并且有办法吗?


谢谢,


Scott

解决方案

Scot,


尝试解析DNS名称到IP地址。当DNS尝试解析不存在
的条目时,通过3- b秒通过

并不罕见。在尝试将主机名解析为IP地址时,DNS服务器无法耗尽其资源耗尽时间。


HTH,


Raymond Lewallen


" Scot" < BL *** @ blank.blank.com>在消息中写道

新闻:c5 ******** @ library1.airnews.net ...

我有以下代码:

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

尝试
IP =
System.Net.Dns.GetHostByName(domainName) .AddressLi st(0).ToString()Catch ex As Exception
IP =" Not Valid"
结束尝试

Console.WriteLine(IP)
系统.Threading.Thread.Sleep(2000)

如果它有一个可解析的域名,比如yahoo.com,它会立即用ip地址回复。但是,如果存在不存在的域名,例如blue2343.com,则需要花费5秒钟来打印Not
Valid。到屏幕。这是为什么?并且有办法吗?

谢谢,

Scott



苏格兰人,


这很可能是因为您的DNS服务器需要花费时间来确定
尝试将DNS名称解析为IP地址。当DNS尝试解析不存在
的条目时,通过3- b秒通过

并不罕见。在尝试将主机名解析为IP地址时,DNS服务器无法耗尽其资源耗尽时间。


HTH,


Raymond Lewallen


" Scot" < BL *** @ blank.blank.com>在消息中写道

新闻:c5 ******** @ library1.airnews.net ...

我有以下代码:

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

尝试
IP =
System.Net.Dns.GetHostByName(domainName) .AddressLi st(0).ToString()Catch ex As Exception
IP =" Not Valid"
结束尝试

Console.WriteLine(IP)
系统.Threading.Thread.Sleep(2000)

如果它有一个可解析的域名,比如yahoo.com,它会立即用ip地址回复。但是,如果存在不存在的域名,例如blue2343.com,则需要花费5秒钟来打印Not
Valid。到屏幕。这是为什么?并且有办法吗?

谢谢,

Scott



嗨雷蒙德


我毫不怀疑你是对的,但是,我曾经认为苏格兰人是

指的是捕捉和投掷的时间例外。


我注意到第一次抛出并发现异常时,.NET

应用程序可能需要很长时间(几秒钟)返回

控制到catch区。


不幸的是对于Scot来说,我不知道为什么会这样,所以我在看

这个帖子有兴趣,如果有什么我可以做的就像

那么好。是否手动抛出异常似乎并不重要

;第一次总是需要几秒钟。


Charles

Raymond Lewallen <太阳神****************** @ nospam.faa.gov>在消息中写道

news:Oq ************* @ tk2msftngp13.phx.gbl ...

Scot,

这很可能是由于您的DNS服务器尝试将DNS名称解析为IP地址所花费的时间。当DNS尝试解析不存在的条目时,通过3-6秒传递并不罕见。在尝试将主机名解析为IP地址时,DNS服务器无法花费大量时间将
耗尽其资源。

HTH,

Raymond Lewallen

苏格兰人 < BL *** @ blank.blank.com>在消息中写道
新闻:c5 ******** @ library1.airnews.net ...

我有以下代码:

昏暗IP,domainName As String
domainName =" yahoo.com"

尝试
IP =


System.Net.Dns.GetHostByName(domainName) .AddressLi st(0).ToString()

Catch ex As Exception
IP =" Not Valid"
结束尝试

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

如果它有一个可解析的域名,比如yahoo.com,它会立即用ip地址回复
。但是,如果其中存在
不存在的域,例如blue2343.com,则需要花费5秒钟来打印Not


有效

到屏幕上。这是为什么?并且有办法吗?

谢谢,

Scott




I have the following code:

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

Try
IP = System.Net.Dns.GetHostByName(domainName).AddressLi st(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

解决方案

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" <bl***@blank.blank.com> wrote in message
news:c5********@library1.airnews.net...

I have the following code:

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

Try
IP = System.Net.Dns.GetHostByName(domainName).AddressLi st(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



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" <bl***@blank.blank.com> wrote in message
news:c5********@library1.airnews.net...

I have the following code:

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

Try
IP = System.Net.Dns.GetHostByName(domainName).AddressLi st(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



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" <Ra******************@nospam.faa.gov> wrote in message
news:Oq*************@tk2msftngp13.phx.gbl...

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" <bl***@blank.blank.com> wrote in message
news:c5********@library1.airnews.net...

I have the following code:

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

Try
IP =


System.Net.Dns.GetHostByName(domainName).AddressLi st(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




这篇关于如果错误,代码需要一段时间才能返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆