2 // Copyright (c) Microsoft Corporation. All rights reserved.
5 namespace System.Activities.Presentation.Validation
7 using System.Activities.Validation;
9 using System.Threading;
10 using System.Windows.Threading;
12 internal sealed class ForegroundValidationSynchronizer<TValidationResult> : ValidationSynchronizer
14 private TaskDispatcher dispatcher;
15 private Func<ValidationReason, CancellationToken, TValidationResult> validationWork;
16 private Action<TValidationResult> updateWork;
18 internal ForegroundValidationSynchronizer(TaskDispatcher dispatcher, Func<ValidationReason, CancellationToken, TValidationResult> validationWork, Action<TValidationResult> updateWork)
20 Fx.Assert(dispatcher != null, "dispatcher should not be null and is ensured by caller.");
21 Fx.Assert(validationWork != null, "validationWork should not be null and is ensured by caller.");
22 Fx.Assert(updateWork != null, "updateWork should not be null and is ensured by caller.");
24 this.dispatcher = dispatcher;
25 this.validationWork = validationWork;
26 this.updateWork = updateWork;
29 internal override void Validate(ValidationReason reason)
31 this.updateWork(this.validationWork(reason, /* cancellationToken = */ CancellationToken.None));
34 internal override void DeactivateValidation()
36 // no-op, we do not need to synchronize change since validation is executing on UI thread.
39 internal override void ActivateValidation()
41 // no-op, we do not need to synchronize change since validation is executing on UI thread.