public async Task SetAndWait() { var MyFlag = new ActionFlag(WaitHalfSecond); var StartTime = DateTime.Now; await MyFlag.SetAndWait(); Assert.That(DateTime.Now.Subtract(StartTime).TotalMilliseconds, Is.InRange(400.0, 600.0)); Assert.AreEqual(1, _Counter, "Counter is not as expected"); }
public async Task SetAndWaitTwiceDelay() { var MyFlag = new ActionFlag(WaitHalfSecond, new TimeSpan(0, 0, 0, 0, 100)); var StartTime = DateTime.Now; MyFlag.Set(); Thread.Sleep(200); await MyFlag.SetAndWait(); Assert.That(DateTime.Now.Subtract(StartTime).TotalMilliseconds, Is.InRange(1100.0, 1300.0)); Assert.AreEqual(2, _Counter, "Counter is not as expected"); }
public async Task SetRuns() { var MyFlag = new ActionFlag(WaitFiftyMs); var EndTime = DateTime.Now.AddSeconds(1.0); while (DateTime.Now < EndTime) { MyFlag.Set(); Interlocked.Exchange(ref _Counter, 0); Thread.Sleep(0); } await MyFlag.SetAndWait(); Assert.AreNotEqual(0, _Counter); }
public async Task SetNoWait() { var MyFlag = new ActionFlag(() => Task.CompletedTask); await MyFlag.SetAndWait(); }