Library/Library.Test/TestWaitAndContinue.cs
C# | Copy Code |
---|---|
WaitAndContinueList work = new WaitAndContinueList(); SampleWork item1, item2; IWaitAndContinue signaled; work.AddWork(item1 = new SampleWork()); work.AddWork(item2 = new SampleWork()); Assert.AreEqual(2, work.Count); Assert.IsFalse(work.IsEmpty); //normally done as a loop: while(work.Perform(timeout)) { } Assert.IsFalse(work.PerformWork(1)); item2.Ready.Set(); Assert.IsTrue(work.PerformWork(0)); Assert.IsTrue(item2.Completed); Assert.IsTrue(item2.Disposed); Assert.IsFalse(work.PerformWork(1)); item1.Cancel.Set(); Assert.IsTrue(work.PerformWork(0, out signaled)); Assert.IsTrue(ReferenceEquals(signaled, item1)); Assert.IsTrue(item1.Completed); Assert.IsTrue(item1.Cancelled); Assert.IsTrue(item1.Disposed); Assert.IsTrue(work.IsEmpty); Assert.AreEqual(0, work.Count); Assert.IsFalse(work.PerformWork(1)); |
VB.NET | Copy Code |
---|---|
Dim work As New WaitAndContinueList() Dim item1 As SampleWork, item2 As SampleWork Dim signaled As IWaitAndContinue work.AddWork(item1 = New SampleWork()) work.AddWork(item2 = New SampleWork()) Assert.AreEqual(2, work.Count) Assert.IsFalse(work.IsEmpty) 'normally done as a loop: while(work.Perform(timeout)) { } Assert.IsFalse(work.PerformWork(1)) item2.Ready.[Set]() Assert.IsTrue(work.PerformWork(0)) Assert.IsTrue(item2.Completed) Assert.IsTrue(item2.Disposed) Assert.IsFalse(work.PerformWork(1)) item1.Cancel.[Set]() Assert.IsTrue(work.PerformWork(0, signaled)) Assert.IsTrue(ReferenceEquals(signaled, item1)) Assert.IsTrue(item1.Completed) Assert.IsTrue(item1.Cancelled) Assert.IsTrue(item1.Disposed) Assert.IsTrue(work.IsEmpty) Assert.AreEqual(0, work.Count) Assert.IsFalse(work.PerformWork(1)) |
Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7