尝试 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 StringdomainName = "yahoo.com"TryIP = System.Net.Dns.GetHostByName(domainName).AddressLi st(0).ToString()Catch ex As ExceptionIP = "Not Valid"End TryConsole.WriteLine(IP)System.Threading.Thread.Sleep(2000)When it has a resolvable domain, like yahoo.com it responds back instantlywith the ip address. However, if there is a domain in there that does notexist, 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 toattempt to resolve the DNS name to an IP address. It is not uncommon for3-6 seconds to pass while DNS attempts to resolve an entry that does notexist. There is no way around the time it takes for a DNS server to exhaustits resources in an attempt to resolve hostnames to ip addresses.HTH,Raymond Lewallen"Scot" <bl***@blank.blank.com> wrote in messagenews: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 "NotValid" to the screen. Why is that? and is there a way around it? Thanks, ScottScot,This is mostly likely due to the time it is taking for your DNS server toattempt to resolve the DNS name to an IP address. It is not uncommon for3-6 seconds to pass while DNS attempts to resolve an entry that does notexist. There is no way around the time it takes for a DNS server to exhaustits resources in an attempt to resolve hostnames to ip addresses.HTH,Raymond Lewallen"Scot" <bl***@blank.blank.com> wrote in messagenews: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 "NotValid" to the screen. Why is that? and is there a way around it? Thanks, ScottHi RaymondI have no doubt that you are correct, however, I had assumed that Scot wasreferring 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 .NETapplication can take a significant time (several seconds) before returningcontrol to the catch block.Unfortunately for Scot, I don''t know why this should be, so I am watchingthis thread with interest in case there is anything I can do about it aswell. It does not seem to matter whether the exception is thrown manuallyeither; the first time always takes several seconds.Charles"Raymond Lewallen" <Ra******************@nospam.faa.gov> wrote in messagenews: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 toexhaust 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 backinstantly with the ip address. However, if there is a domain in there that doesnot 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 这篇关于如果错误,代码需要一段时间才能返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-29 05:46
查看更多