views:

41

answers:

2

I need to validate a control input on losing focus. Normally I'd use the Validating event. However this process involves checking the entered data against a local database of over 280,000 postal codes. I'd like for this validation to occur asynchronously since there is no requirement for the user to wait for it before they can enter the remaining form data.

My first thought was to encapsulate the validation logic in its own method, bind a delegate to it and use BeginInvoke() and EndInvoke inside the control validation event since no possible result of the validation will require Cancel=True (they will simply change the control forecolor).

Is there any better method?

+3  A: 

You might want to look at a BackgroundWorker

TJMonk15
Perfect! It precisely what I need. And the level of control offered by ProgressChanged and RunWorkerCompleted events beats my delegate. Thank you :)
Krugar
+1  A: 

You might find a BackgroundWorker a good method of doing this.

One thing to consider is the user trying to submit the form before your validation has finished running.

Pondidum
+1 Thanks Pondidum. TJMonk beat you by a few seconds. But that means exactly I should thank you also.
Krugar