本文整理汇总了VB.NET中System.Net.Dns.BeginGetHostEntry方法的典型用法代码示例。如果您正苦于以下问题:VB.NET Dns.BeginGetHostEntry方法的具体用法?VB.NET Dns.BeginGetHostEntry怎么用?VB.NET Dns.BeginGetHostEntry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。
在下文中一共展示了Dns.BeginGetHostEntry方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: ResolveState
' Signals when the resolve has finished.
Dim Shared GetHostEntryFinished As ManualResetEvent = New ManualResetEvent(False)
' Define the state object for the callback.
' Use hostName to correlate calls with the proper result.
Class ResolveState
Dim hostName As String
Dim resolvedIPs As IPHostEntry
Public Sub New(host As String)
hostName = host
End Sub
Public Property IPs AS IPHostEntry
Get
Return resolvedIPs
End Get
Set
resolvedIPs = value
End Set
End Property
Public Property host As String
Get
Return hostName
End Get
Set
hostName = value
End Set
End Property
End Class
' Record the IPs in the state object for later use.
Shared Sub GetHostEntryCallback(ar As IAsyncResult)
Dim ioContext As ResolveState = ar.AsyncState
ioContext.IPs = Dns.EndGetHostEntry(ar)
GetHostEntryFinished.Set()
End Sub
' Determine the Internet Protocol (IP) addresses for
' this host asynchronously.
Shared Sub DoGetHostEntryAsync(hostname As String)
GetHostEntryFinished.Reset()
Dim ioContext As ResolveState = New ResolveState(hostname)
Dns.BeginGetHostEntry(ioContext.host,AddressOf GetHostEntryCallback, ioContext)
' Wait here until the resolve completes (the callback
' calls .Set())
GetHostEntryFinished.WaitOne()
Console.WriteLine($"EndGetHostEntry({ioContext.host}) returns:")
Dim addresses As IPAddress() = ioContext.IPs.AddressList
Dim index As Integer
For index = 0 To addresses.Length - 1
Console.WriteLine($" {addresses(index)}")
Next index
End Sub