PowerTCP Sockets for .NET

from $349.00
Available Platforms
<

Windows Forms DNS MX Lookup C# Code Example

See all PowerTCP Sockets for .NET Samples and Code Examples

 

The following C# example demonstrates an MX Lookup DNS operation in a Windows Forms environment. The application retrieves mail hosts for a specified email address. The session is executed asynchronously, without blocking the UI.

 

private void buttonLookup_Click(object sender, EventArgs e)
{
    //This application has a User-Interface, which we do not want to block.
    //Start launches the specified method on a worker thread.
    dns1.Start(new DnsThreadStart(doLookup), "myAddress@gmail.com");
}

private void doLookup(DnsSlave slave, object address)
{
    //Lookup mail servers associated with the passed in address.
    MxHostEntry[] servers = slave.GetMxHostEntries(address.ToString(), dns1.Servers[0]);

    //Build a string from the results and marshal it to the UI thread via the UserState event.
    string results = "The following mail servers were returned:\r\n";
    for (int i = 0; i < servers.Length; i++)
         results += servers[i].HostName + " (" + servers[i].Preference.ToString() + ")\r\n";
    dns1.Marshal(results, null);
}

private void dns1_UserState(object sender, UserStateEventArgs e)
{
    //This event is raised on the UI thread
    //when DNS results are marshaled from a worker thread.
    MessageBox.Show(e.Message);
}

 

To download a trial please visit the PowerTCP Sockets for .NET product page.