コード例 #1
0
            public void AdquiresTheLockDuringTheExecutionAndReleaseItAtTheEnd()
            {
                var @event  = new AutoResetEvent(false);
                var context = new SynchronizationContext();

                Assert.IsFalse(context.IsLockAcquired);
                context.Enqueue(() => Assert.IsTrue(context.IsLockAcquired), (sender, args) => @event.Set());
                @event.WaitOne();
                Assert.IsFalse(context.IsLockAcquired);
            }
コード例 #2
0
            public void AdquiresTheLockDuringTheExecutionAndReleaseItAtTheEndAndReturnAValue()
            {
                var @event  = new AutoResetEvent(false);
                var context = new SynchronizationContext();

                Assert.IsFalse(context.IsLockAcquired);
                int expected = new Random().Next(50, 100);
                int result   = 0;

                context.Enqueue(() =>
                {
                    Assert.IsTrue(context.IsLockAcquired);
                    return(expected);
                }, (sender, args) =>
                {
                    result = (int)args.Result;
                    @event.Set();
                });
                @event.WaitOne();
                Assert.IsFalse(context.IsLockAcquired);
                Assert.AreEqual(expected, result);
            }
コード例 #3
0
 public void AdquiresTheLockDuringTheExecutionAndReleaseItAtTheEnd()
 {
     var @event = new AutoResetEvent(false);
     var context = new SynchronizationContext();
     Assert.IsFalse(context.IsLockAcquired);
     context.Enqueue(() => Assert.IsTrue(context.IsLockAcquired), (sender, args) => @event.Set());
     @event.WaitOne();
     Assert.IsFalse(context.IsLockAcquired);
 }
コード例 #4
0
 public void AdquiresTheLockDuringTheExecutionAndReleaseItAtTheEndAndReturnAValue()
 {
     var @event = new AutoResetEvent(false);
     var context = new SynchronizationContext();
     Assert.IsFalse(context.IsLockAcquired);
     int expected = new Random().Next(50, 100);
     int result = 0;
     context.Enqueue(() =>
     {
         Assert.IsTrue(context.IsLockAcquired);
         return expected;
     }, (sender, args) =>
         {
             result = (int)args.Result;
             @event.Set();
         });
     @event.WaitOne();
     Assert.IsFalse(context.IsLockAcquired);
     Assert.AreEqual(expected, result);
 }