PowerTCP Sockets for .NET | Windows Forms DNS MX Lookup Code Example
The following example demonstrates a 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);
//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";
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.