NET Email Validation
ValidationCompleteEvent Event
Example 






KellermanSoftware.NetEmailValidation Namespace > EmailValidation Class : ValidationCompleteEvent Event
Occurs when validation is complete for asynchronous validation.
Syntax
'Declaration
 
Public Event ValidationCompleteEvent As System.ComponentModel.AsyncCompletedEventHandler
'Usage
 
Dim instance As EmailValidation
Dim handler As System.ComponentModel.AsyncCompletedEventHandler
 
AddHandler instance.ValidationCompleteEvent, handler
public event System.ComponentModel.AsyncCompletedEventHandler ValidationCompleteEvent
public event ValidationCompleteEvent: System.ComponentModel.AsyncCompletedEventHandler; 
In JScript, you can handle the events defined by another class, but you cannot define your own.
public: __event System.ComponentModel.AsyncCompletedEventHandler* ValidationCompleteEvent
public:
event System.ComponentModel.AsyncCompletedEventHandler^ ValidationCompleteEvent
Event Data

The event handler receives an argument of type System.ComponentModel.AsyncCompletedEventArgs containing data related to this event. The following AsyncCompletedEventArgs properties provide information specific to this event.

PropertyDescription
 
 
 
Example
public void Example()
{
    EmailValidation emailValidator = new EmailValidation(); //Trial Mode
    //EmailValidation emailValidator = new EmailValidation("place user name here", "place license key here"); //License Mode
     
    emailValidator.FromEmail = "someone@somewhere.com";
    emailValidator.FromMailServer = "mail.somewhere.com";
     
    //Create a list of 100 email addresses with an id
    Dictionary<string, string> emailAddresses = new Dictionary<string, string>();
     
    for (int i = 1; i <= 100; i++)
        emailAddresses.Add(i.ToString(),string.Format("johnsmith{0}@hotmail.com", i));
     
    List<ValidationOptions> options = emailValidator.BestConnectionOptions();
     
    //Attach Events                
    emailValidator.ProgressEvent += new EmailValidation.ProgressChangedEventHandler(ProgressEvent);
    emailValidator.ValidationCompleteEvent += new AsyncCompletedEventHandler(CompletionEvent);
    emailValidator.ResponseReceivedEvent += new EmailValidation.ResponseReceivedEventHandler(ResponseReceivedEvent);
     
    //Begin asynchronous validation
    emailValidator.ValidateListAsync(emailAddresses, options);
     
    while (emailValidator.IsBusy)
    {
        //Sleep 1 second
        System.Threading.Thread.Sleep(1000);
    }
     
    //Remove the event connections
    emailValidator.ProgressEvent -= new EmailValidation.ProgressChangedEventHandler(ProgressEvent);
    emailValidator.ValidationCompleteEvent -= new AsyncCompletedEventHandler(CompletionEvent);
    emailValidator.ResponseReceivedEvent -= new EmailValidation.ResponseReceivedEventHandler(ResponseReceivedEvent);
}
 
 
public void CompletionEvent(object sender, AsyncCompletedEventArgs e)
{
    Console.WriteLine("Finished. Validated emails");
}
 
public void ProgressEvent(object sender, ProgressEventArgs args)
{
    Console.WriteLine(string.Format("{0}% ({1} of {2}", args.ProgressPercentage, args.EmailsProcessed, args.TotalEmailsToProcess));
}
 
public void ResponseReceivedEvent(object sender, Result result)
{
    if (result.IsValid)
    {
        //Do something
    }
    else
    {
        //Do something else
    }
 
    Console.WriteLine(result.Log);
}
Public Sub Example()
    Dim emailValidator As EmailValidation = New EmailValidation() 'Trial Mode
    'Dim emailValidator As EmailValidation = New EmailValidation("place user name here", "place license key here") 'License Mode
 
    emailValidator.FromEmail = "someone@somewhere.com"
    emailValidator.FromMailServer = "mail.somewhere.com"
     
    'Create a list of 100 email addresses with an id
    Dim emailAddresses As Dictionary(Of String, String) = New Dictionary(Of String, String)()
     
    For i As Integer = 1 To 100
        emailAddresses.Add(i.ToString(),String.Format("johnsmith{0}@hotmail.com", i))
    Next i
     
    Dim options As List(Of ValidationOptions) = emailValidator.BestConnectionOptions()
     
    'Attach Events                
    AddHandler emailValidator.ProgressEvent, AddressOf ProgressEvent
    AddHandler emailValidator.ValidationCompleteEvent, AddressOf CompletionEvent
    AddHandler emailValidator.ResponseReceivedEvent, AddressOf ResponseReceivedEvent
     
    'Begin asynchronous validation
    emailValidator.ValidateListAsync(emailAddresses, options)
     
    Do While emailValidator.IsBusy
        'Sleep 1 second
        System.Threading.Thread.Sleep(1000)
    Loop
     
    'Remove the event connections
    RemoveHandler emailValidator.ProgressEvent, AddressOf ProgressEvent
    RemoveHandler emailValidator.ValidationCompleteEvent, AddressOf CompletionEvent
    RemoveHandler emailValidator.ResponseReceivedEvent, AddressOf ResponseReceivedEvent
End Sub
    
 
Public Sub CompletionEvent(ByVal sender As Object, ByVal e As AsyncCompletedEventArgs)
    Console.WriteLine("Finished. Validated emails")
End Sub
 
Public Sub ProgressEvent(ByVal sender As Object, ByVal args As ProgressEventArgs)
    Console.WriteLine(String.Format("{0}% ({1} of {2}", args.ProgressPercentage, args.EmailsProcessed, args.TotalEmailsToProcess))
End Sub
 
Public Sub ResponseReceivedEvent(ByVal sender As Object, ByVal result As Result)
    If result.IsValid Then
        'Do something
    Else
        'Do something else
    End If
 
    Console.WriteLine(result.Log)
End Sub
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also