EditContext.ValidateAsync(CancellationToken) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Validates this EditContext asynchronously.
Cancels any pending field-level async validation tasks, invokes the synchronous
OnValidationRequested handlers, then invokes and awaits the asynchronous
OnValidationRequestedAsync handlers concurrently. Exceptions from synchronous
handlers propagate to the caller, matching Validate(). Any non-cancellation
exception thrown by an asynchronous handler is contained: the form is marked as faulted
(observable via the parameterless IsValidationFaulted()) and the method
returns false.
While the asynchronous portion is in flight, the parameterless
IsValidationPending() returns true so applications can show a global
"validating..." indicator without wrapping the call themselves. The form-level
IsValidationFaulted() result is updated only when a pass completes; it is
preserved across caller-cancelled passes.
public System.Threading.Tasks.Task<bool> ValidateAsync(System.Threading.CancellationToken cancellationToken = default);
member this.ValidateAsync : System.Threading.CancellationToken -> System.Threading.Tasks.Task<bool>
Public Function ValidateAsync (Optional cancellationToken As CancellationToken = Nothing) As Task(Of Boolean)
Parameters
- cancellationToken
- CancellationToken
A token that signals cancellation of this validation pass. The token is exposed to async handlers via CancellationToken. If the caller cancels the token, this method throws OperationCanceledException; the form is not marked as faulted in that case and the previous form-level fault state is preserved. The token bounds the in-flight pass only; field-level validation tasks that start independently during the awaited window (for example, from user edits) are not linked to this token and continue running.
Returns
True if there are no validation messages after validation and no async handler faulted; otherwise false.
Exceptions
Thrown when cancellationToken
is cancelled before or during the validation pass.
Remarks
Validation must not be re-entered. Do not call Validate() or ValidateAsync(CancellationToken) from inside an OnValidationRequested, OnValidationRequestedAsync, or OnValidationStateChanged handler attached to the same EditContext; doing so produces undefined behavior.