Wait() public method

Blocks the current thread until it can enter the SemaphoreLight.
public Wait ( ) : void
return void
コード例 #1
0
        public void WaitTest()
        {
            const int sleepTime = 200; 
            const int initialCount = 2;
            var target = new SemaphoreLight(initialCount);

            var start = DateTime.Now;

            target.Wait();
            target.Wait();

            Assert.IsTrue((DateTime.Now - start).TotalMilliseconds < 50);

            var releaseThread = new Thread(
                () =>
                    {
                        Thread.Sleep(sleepTime);
                        target.Release();
                    });
            releaseThread.Start();

            target.Wait();

            var end = DateTime.Now;
            var elapsed = end - start;

            Assert.IsTrue(elapsed.TotalMilliseconds > 200);
            Assert.IsTrue(elapsed.TotalMilliseconds < 250);
        }
コード例 #2
0
ファイル: SemaphoreLightTest.cs プロジェクト: pecegit/sshnet
 public void WaitTest()
 {
     int initialCount = 0; // TODO: Initialize to an appropriate value
     SemaphoreLight target = new SemaphoreLight(initialCount); // TODO: Initialize to an appropriate value
     target.Wait();
     Assert.Inconclusive("A method that does not return a value cannot be verified.");
 }