/// <summary> /// Adds the validator to this composite validator. /// </summary> /// <param name="validator">The validator to add.</param> /// <exception cref="ArgumentNullException">The <paramref name="validator" /> is <c>null</c>.</exception> public void Add(IValidator validator) { Argument.IsNotNull("validator", validator); _synchronizationContext.Execute( () => { if (!_validators.Contains(validator)) { _validators.Add(validator); } }); }
private void RunPollLoop(SynchronizationContext syncContext, Action <TPollRetVal> processFunc) { this.stopSignal.Reset(); this.EmptyPollCallCount = 0; TPollRetVal polledValue; while (this.WaitForPayloadInternal(out polledValue, syncContext)) { TPollRetVal polledValTemp = polledValue; syncContext.Execute(() => processFunc(polledValTemp)); } }
private bool WaitForPayloadInternal(out TPollRetVal payload, SynchronizationContext syncCtx) { payload = default(TPollRetVal); int delayMillisec = 0; int delayIncrementMillisec = this.DelayAfterFirstEmptyPollMillisec; while (this.SleepAfterEmptyPollCall(delayMillisec)) { Tuple <bool, TPollRetVal> retVal = syncCtx.Execute(() => this.Poll()); payload = retVal.Item2; if (retVal.Item1) { this.PollCallCountWithPayload++; return(true); } this.EmptyPollCallCount++; // Poll came back empty. this.IncreasePollDelay(ref delayMillisec, ref delayIncrementMillisec); } return(false); }
public static void Execute(System.Action act) { var execute = true; var intercepter = new SynchronizationContext(Mux.Forms.mainThread); Mux.Forms.mainThread = intercepter; try { var task = System.Threading.Tasks.Task.Run(() => { try { act(); } finally { Mux.Forms.mainThread.Post(state => { execute = false; }, null); } }); while (execute) { intercepter.Execute(); } task.Wait(); } finally { Mux.Forms.mainThread = intercepter.mainThread; } }
/// <summary> /// Adds an expiration policy to the composition. /// </summary> /// <param name="expirationPolicy"> /// The expiration policy. /// </param> /// <returns> /// The <see cref="CompositeExpirationPolicy"/>. /// </returns> public CompositeExpirationPolicy Add(ExpirationPolicy expirationPolicy) { _synchronizationContext.Execute(() => _expirationPolicies.Add(expirationPolicy)); return(this); }