PowerTCP Sockets for .NET
Start(DnsThreadStart,Object) Method
Example 




DnsThreadStart delegate specifies the method to execute.
Information to pass to the worker delegate method; can be null.
Starts a worker thread on which the specified delegate method executes.
Syntax
'Declaration
 
Public Overloads Sub Start( _
   ByVal worker As DnsThreadStart, _
   ByVal state As Object _
) 
'Usage
 
Dim instance As Dns
Dim worker As DnsThreadStart
Dim state As Object
 
instance.Start(worker, state)
public void Start( 
   DnsThreadStart worker,
   object state
)
public: void Start( 
   DnsThreadStart* worker,
   Object* state
) 
public:
void Start( 
   DnsThreadStart^ worker,
   Object^ state
) 

Parameters

worker
DnsThreadStart delegate specifies the method to execute.
state
Information to pass to the worker delegate method; can be null.
Remarks

This method provides an easy means for executing multiple DNS resolutions in parallel. The default IPv4 socket interface is used.

Unhandled exceptions occurring on the worker thread are reported via the Error event.

Example
The following example demonstrates performing a DNS lookup of a provided hostname, and an MX record lookup of a provided email address.
private void button1_Click(object sender, EventArgs e)
{
    dns1.Start(doMxLookup, EmailToResolveTextbox.Text);
}

private void button2_Click(object sender, EventArgs e)
{
    dns1.Start(doHostLookup, HostToResolveTextbox.Text);
}

/// <summary>
/// Performs an MX record lookup of the provided email address.
/// </summary>
/// <param name="slave">Object used to perform DNS lookup</param>
/// <param name="state">Passed in from the 2nd parameter of Dns.Start(). Email address to lookup.</param>
private void doMxLookup(DnsSlave slave, object state)
{
    MxHostEntry[] hostEntries = slave.GetMxHostEntries(state.ToString());
    string results = "The following mail servers were returned for " + state.ToString() + ":" + Environment.NewLine;
    foreach (MxHostEntry hostEntry in hostEntries)
        results += hostEntry.HostName + " : Preference: " + hostEntry.Preference.ToString() + Environment.NewLine;
    //Marshal result to the UI for display
    dns1.Marshal(results, null);
}

/// <summary>
/// Performs a DNS lookup of the provided hostname.
/// </summary>
/// <param name="slave">Object used to perform DNS lookup</param>
/// <param name="state">Passed in from the 2nd parameter of Dns.Start(). Hostname to lookup.</param>
private void doHostLookup(DnsSlave slave, object state)
{
    System.Net.IPHostEntry hostEntry = slave.GetHostEntry(state.ToString());
    string results = "The following IP addresses were returned for " + state.ToString() + ":" + Environment.NewLine;
    foreach (System.Net.IPAddress address in hostEntry.AddressList)
        results += address.ToString() + Environment.NewLine;
    //Marshal result to the UI for display
    dns1.Marshal(results, null);
}

/// <summary>
/// Raised when Dns.Marshal(string, object) is called.
/// </summary>
private void dns1_UserState(object sender, UserStateEventArgs e)
{
    textBox1.AppendText(e.Message + Environment.NewLine);
}
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
    dns1.Start(AddressOf doMxLookup, EmailToResolveTextbox.Text)
End Sub

Private Sub button2_Click(ByVal sender As Object, ByVal e As EventArgs)
    dns1.Start(AddressOf doHostLookup, HostToResolveTextbox.Text)
End Sub

''' <summary>
''' Performs an MX record lookup of the provided email address.
''' </summary>
''' <param name="slave">Object used to perform DNS lookup</param>
''' <param name="state">Passed in from the 2nd parameter of Dns.Start(). Email address to lookup.</param>
Private Sub doMxLookup(ByVal slave As DnsSlave, ByVal state As Object)
    Dim hostEntries() As MxHostEntry = slave.GetMxHostEntries(state.ToString())
    Dim results As String = "The following mail servers were returned for " & state.ToString() & ":" & Environment.NewLine
    For Each hostEntry As MxHostEntry In hostEntries
        results &= hostEntry.HostName & " : Preference: " & hostEntry.Preference.ToString() & Environment.NewLine
    Next hostEntry
    'Marshal result to the UI for display
    dns1.Marshal(results, Nothing)
End Sub

''' <summary>
''' Performs a DNS lookup of the provided hostname.
''' </summary>
''' <param name="slave">Object used to perform DNS lookup</param>
''' <param name="state">Passed in from the 2nd parameter of Dns.Start(). Hostname to lookup.</param>
Private Sub doHostLookup(ByVal slave As DnsSlave, ByVal state As Object)
    Dim hostEntry As System.Net.IPHostEntry = slave.GetHostEntry(state.ToString())
    Dim results As String = "The following IP addresses were returned for " & state.ToString() & ":" & Environment.NewLine
    For Each address As System.Net.IPAddress In hostEntry.AddressList
        results &= address.ToString() & Environment.NewLine
    Next address
    'Marshal result to the UI for display
    dns1.Marshal(results, Nothing)
End Sub

''' <summary>
''' Raised when Dns.Marshal(string, object) is called.
''' </summary>
Private Sub dns1_UserState(ByVal sender As Object, ByVal e As UserStateEventArgs)
    textBox1.AppendText(e.Message & Environment.NewLine)
End Sub
See Also

Reference

Dns Class
Dns Members
Overload List


PowerTCP Sockets for .NET Documentation Version 4.5
© 2018 Dart Communications. All Rights Reserved.
Send comments on this topic