GetValue() public method

Retrieve the cell's value, waiting for the given timeout if no value is immediately available.

If a value is present in the cell at the time the call is made, the call will return immediately. Otherwise, the calling thread blocks until either a value appears, or operation times out.

If no value was available before the timeout, an exception is thrown.

public GetValue ( System.TimeSpan timeout ) : object
timeout System.TimeSpan
return object
        public void TestBgShort()
        {
            BlockingCell k = new BlockingCell();
            SetAfter(TimingInterval, k, 123);

            ResetTimer();
            object v;
            bool r = k.GetValue(TimingInterval * 2, out v);
            Assert.Less(TimingInterval - SafetyMargin, ElapsedMs());
            Assert.IsTrue(r);
            Assert.AreEqual(123, v);
        }
        public void TestTimeoutLong()
        {
            BlockingCell k = new BlockingCell();

            ResetTimer();
            object v;
            bool r = k.GetValue(TimingInterval, out v);
            Assert.Less(TimingInterval - SafetyMargin, ElapsedMs());
            Assert.IsTrue(!r);
            Assert.AreEqual(null, v);
        }
        public void TestTimeoutNegative()
        {
            BlockingCell k = new BlockingCell();

            ResetTimer();
            object v;
            bool r = k.GetValue(-10000, out v);
            Assert.Greater(SafetyMargin, ElapsedMs());
            Assert.IsTrue(!r);
            Assert.AreEqual(null, v);
        }
        public void TestBackgroundUpdateFails()
        {
            BlockingCell k = new BlockingCell();
            SetAfter(TimingInterval * 2, k, 123);

            ResetTimer();
            Assert.Throws<TimeoutException>(() => k.GetValue(TimingInterval));
        }
        public void TestGetValueWhichDoesNotTimeOut()
        {
            BlockingCell k = new BlockingCell();
            k.Value = 123;

            ResetTimer();
            var v = k.GetValue(TimingInterval);
            Assert.Greater(SafetyMargin, ElapsedMs());
            Assert.AreEqual(123, v);
        }
        public void TestTimeoutLong()
        {
            BlockingCell k = new BlockingCell();

            ResetTimer();
            object v;
            bool r = k.GetValue((int) TimingInterval.TotalMilliseconds, out v);
            Assert.Less((int)TimingInterval.Subtract(SafetyMargin).TotalMilliseconds, ElapsedMs());
            Assert.IsTrue(!r);
            Assert.AreEqual(null, v);
        }
        public void TestBackgroundUpdateSucceedsWithInfiniteTimeoutTimeSpan()
        {
            BlockingCell k = new BlockingCell();
            SetAfter(TimingInterval, k, 123);

            ResetTimer();
            var v = k.GetValue(Timeout.InfiniteTimeSpan);
            Assert.Less(TimingInterval - SafetyMargin, ElapsedMs());
            Assert.AreEqual(123, v);
        }
 public void TestGetValueWhichDoesTimeOut()
 {
     BlockingCell k = new BlockingCell();
     ResetTimer();
     Assert.Throws<TimeoutException>(() => k.GetValue(TimingInterval));
 }
 public void TestGetValueWhichDoesTimeOutWithTimeSpan()
 {
     BlockingCell k = new BlockingCell();
     ResetTimer();
     Assert.Throws<TimeoutException>(() => k.GetValue(TimeSpan.FromMilliseconds(TimingInterval)));
 }
        public void TestTimeoutLong()
        {
            BlockingCell k = new BlockingCell();

            ResetTimer();
            object v;
            bool r = k.GetValue(250, out v);
            Assert.Greater(ElapsedMs(), 200);
            Assert.IsTrue(!r);
            Assert.AreEqual(null, v);
        }
        public void TestBgLong()
        {
            BlockingCell k = new BlockingCell();
            SetAfter(150, k, 123);

            ResetTimer();
            object v;
            bool r = k.GetValue(100, out v);
            Assert.Greater(110, ElapsedMs());
            Assert.IsTrue(!r);
            Assert.AreEqual(null, v);
        }
        public void TestTimeoutInfinite()
        {
            BlockingCell k = new BlockingCell();
            SetAfter(250, k, 123);

            ResetTimer();
            object v;
            bool r = k.GetValue(Timeout.Infinite, out v);
            Assert.Greater(ElapsedMs(), 200);
            Assert.IsTrue(r);
            Assert.AreEqual(123, v);
        }
        public void TestBgShort()
        {
            BlockingCell k = new BlockingCell();
            SetAfter(50, k, 123);

            ResetTimer();
            object v;
            bool r = k.GetValue(100, out v);
            Assert.Greater(ElapsedMs(), 40);
            Assert.IsTrue(r);
            Assert.AreEqual(123, v);
        }
        public void TestBgLong()
        {
            BlockingCell k = new BlockingCell();
            SetAfter((int) TimingInterval.TotalMilliseconds * 2, k, 123);

            ResetTimer();
            object v;
            bool r = k.GetValue((int) TimingInterval.TotalMilliseconds, out v);
            Assert.Greater((int)TimingInterval.Add(SafetyMargin).TotalMilliseconds, ElapsedMs());
            Assert.IsTrue(!r);
            Assert.AreEqual(null, v);
        }
        public void TestBgLong()
        {
            BlockingCell k = new BlockingCell();
            SetAfter(TimingInterval * 2, k, 123);

            ResetTimer();
            object v;
            bool r = k.GetValue(TimingInterval, out v);
            Assert.Greater(TimingInterval + SafetyMargin, ElapsedMs());
            Assert.IsTrue(!r);
            Assert.AreEqual(null, v);
        }
        public void TestGetValueWithTimeoutInfinite()
        {
            BlockingCell k = new BlockingCell();
            SetAfter(TimingInterval, k, 123);

            ResetTimer();
            var v = k.GetValue(Timeout.Infinite);
            Assert.Less(TimingInterval - SafetyMargin, ElapsedMs());
            Assert.AreEqual(123, v);
        }
        public void TestTimeoutShort()
        {
            BlockingCell k = new BlockingCell();
            k.Value = 123;

            ResetTimer();
            object v;
            bool r = k.GetValue(TimingInterval, out v);
            Assert.Greater(SafetyMargin, ElapsedMs());
            Assert.IsTrue(r);
            Assert.AreEqual(123, v);
        }
        public void TestTimeoutInfinite()
        {
            BlockingCell k = new BlockingCell();
            SetAfter((int) TimingInterval.TotalMilliseconds, k, 123);

            ResetTimer();
            object v;
            bool r = k.GetValue(Timeout.Infinite, out v);
            Assert.Less((int)TimingInterval.Subtract(SafetyMargin).TotalMilliseconds, ElapsedMs());
            Assert.IsTrue(r);
            Assert.AreEqual(123, v);
        }