Query Records Asynchronously using the MailExchangeRecord  class.

The following example demonstrates querying Mail Exchange (MX) records, asynchronously, using the static method called GetMailExchangeRecordsAsync(). When the method has finished executing, the call back method RetrieveMailExchangeRecord() will be called.

[C#]

using System;
using aspNetDns;
using aspNetDns.Records;
namespace consoleTest
{
	class Class1
	{
		[STAThread]
		static void Main(string[] args)
		{
			string LookupRecord = "microsoft.com";
			MailExchangeRecord.GetMailExchangeRecordsAsync( LookupRecord,  new MailExchangeRecordDelegate( RetrieveMailExchangeRecord) );
		}

		private static void RetrieveMailExchangeRecord(MailExchangeRecord[] records)
		{
			if( records.Length > 0 )
			{
				foreach( MailExchangeRecord r in records )
				{
					Console.WriteLine( r.Exchange);
					Console.WriteLine( r.Preference.ToString()  );
				}
			}
			else
				Console.WriteLine( "No records were found.");

			Console.ReadLine();
		}
	}
}





 

[VB.NET]

Imports aspNetDns
Imports aspNetDns.Records
Module Module1

    Sub Main()

        Dim LookupRecord As String = "microsoft.com"
        MailExchangeRecord.GetMailExchangeRecordsAsync(LookupRecord, New MailExchangeRecordDelegate(AddressOf RetrieveMailExchangeRecord))

    End Sub

    Private Sub RetrieveMailExchangeRecord(ByVal records() As MailExchangeRecord)
        If records.Length > 0 Then
            Dim r As AddressRecord
            For Each r In records
                Console.WriteLine(r.Exchange)
                Console.WriteLine(r.Preference.ToString())
            Next r
        Else
            Console.WriteLine("No records were found.")
        End If
        Console.ReadLine()
    End Sub


End Module