Displaying progress while validating e-mails
When the email list to validate is long and your application may take time to validate all e-mails, you may wish to show the progress of the validation to the user. The ComponentSoft UltimateEmailValidator component provides progress notification through the Progress event. The Progress event is raised periodically while e-mail validation is in progress, making accessible necessary data to display progress information, such as e-mail address and validation level.
The following steps show you how to use the Progress event to show progress information while validating e-mail addresses:
Displaying progress while validating e-mail addresses
- Add using directives to your code to create aliases for existing namespaces and avoid having to type the fully qualified type names. The code looks similar to the following:
C#
Copy Codeusing ComponentSoft.Net;VB.NET
Copy CodeImports ComponentSoft.Net - Create a new instance of the EmailValidator class.
C#
Copy Code// Create a new instance of the EmailValidator class.
EmailValidator client = new EmailValidator();VB.NET
Copy Code‘ Create a new instance of the EmailValidator class.
Dim client As New EmailValidator() - Now pass the e-mail list file you want to validate to the ValidateTextFile method. The code looks similar to the following:
C#
Copy Code// Register an event handler.
em.Progress += em_Progress;
try
{
em.ValidateTextFile(“c:\\EmailList.txt”);
}
catch (EmailValidatorException exc2)
{
Console.WriteLine(“EmailValidatorException: “ + exc2.Message);
}VB.NET
Copy Code‘ Register an event handler.
AddHandler em.Progress, AddressOf em_Progress
Try
em.ValidateTextFile(“c:\EmailList.txt”)
Catch exc2 As EmailValidatorException
Console.WriteLine(“EmailValidatorException: “ & exc2.Message)
End Try
Final example code
| C# | Copy Code |
|---|---|
|
static void Main()
{ EmailValidator em = new EmailValidator(); // Register an event handler. em.Progress += em_Progress; try { em.ValidateTextFile(“c:\\EmailList.txt”); } catch (EmailValidatorException exc2) { Console.WriteLine(“EmailValidatorException: “ + exc2.Message); } } static void em_Progress(object sender, EmailValidatorProgressEventArgs e) { Console.WriteLine(“Validating email ‘{0}’ at level {1}. Completed {2}%”, e.EmailAddress, e.Level.ToString(), e.ProgressPercentage); } |
|
| VB.NET | Copy Code |
|---|---|
|
Sub Main()
Dim em As New EmailValidator() ‘ Register an event handler. AddHandler em.Progress, AddressOf em_Progress Try em.ValidateTextFile(“c:\EmailList.txt”) Catch exc2 As EmailValidatorException Console.WriteLine(“EmailValidatorException: “ & exc2.Message) End Try End Sub Private Sub em_Progress(ByVal sender As Object, ByVal e As EmailValidatorProgressEventArgs) Console.WriteLine(“Validating email ‘{0}’ at level {1}. Completed {2}%”, e.EmailAddress, e.Level.ToString(), e.ProgressPercentage) End Sub |
|
Advertisement
Categories: Uncategorized