コード例 #1
0
        public void AsyncBlockUntilCompleteWithException()
        {
            InvalidOperationException terminatingException = new InvalidOperationException("Failure succeeded");
            AsynchronousTask          task = new AsynchronousTask(1, terminatingException);
            IAsyncResult ar = task.BeginDoTask(null, this);

            Assert.Throws <InvalidOperationException>(delegate { task.EndDoTask(ar); });
        }
コード例 #2
0
        public void AsyncBlockUntilComplete()
        {
            AsynchronousTask task = new AsynchronousTask(1);
            IAsyncResult     ar   = task.BeginDoTask(null, this);

            Stopwatch timer = Stopwatch.StartNew();

            task.EndDoTask(ar);
            timer.Stop();

            Assert.True(ar.IsCompleted);
            Assert.False(ar.CompletedSynchronously);
            Assert.True(timer.ElapsedMilliseconds > 500L);
        }
コード例 #3
0
        public void AsyncCallBackNotification()
        {
            CallBackHelper callBackRecorder = new CallBackHelper();
            AsynchronousTask task = new AsynchronousTask(1);

            IAsyncResult ar = task.BeginDoTask(callBackRecorder.CallBack, this);
            Thread.Sleep(2000);

            Assert.Same(ar, callBackRecorder.Result);
            Assert.True(ar.IsCompleted);
            Assert.False(ar.CompletedSynchronously);
            
            task.EndDoTask(ar);  // should not throw
        }
コード例 #4
0
        public void AsyncCallBackNotificationWithException()
        {
            CallBackHelper callBackRecorder = new CallBackHelper();
            InvalidOperationException terminatingException = new InvalidOperationException("Failure succeeded");
            AsynchronousTask<String> task = new AsynchronousTask<String>(1, terminatingException);

            IAsyncResult ar = task.BeginDoTask(callBackRecorder.CallBack, this);
            Thread.Sleep(2000);

            Assert.Same(ar, callBackRecorder.Result);
            Assert.True(ar.IsCompleted);
            Assert.False(ar.CompletedSynchronously);

            Assert.Throws<InvalidOperationException>(delegate { task.EndDoTask(ar); });
        }
コード例 #5
0
        public void AsyncCallBackNotification()
        {
            CallBackHelper   callBackRecorder = new CallBackHelper();
            AsynchronousTask task             = new AsynchronousTask(1);

            IAsyncResult ar = task.BeginDoTask(callBackRecorder.CallBack, this);

            Thread.Sleep(2000);

            Assert.Same(ar, callBackRecorder.Result);
            Assert.True(ar.IsCompleted);
            Assert.False(ar.CompletedSynchronously);

            task.EndDoTask(ar);  // should not throw
        }
コード例 #6
0
        public void AsyncCallBackNotificationWithException()
        {
            CallBackHelper            callBackRecorder     = new CallBackHelper();
            InvalidOperationException terminatingException = new InvalidOperationException("Failure succeeded");
            AsynchronousTask          task = new AsynchronousTask(1, terminatingException);

            IAsyncResult ar = task.BeginDoTask(callBackRecorder.CallBack, this);

            Thread.Sleep(2000);

            Assert.Same(ar, callBackRecorder.Result);
            Assert.True(ar.IsCompleted);
            Assert.False(ar.CompletedSynchronously);

            Assert.Throws <InvalidOperationException>(delegate { task.EndDoTask(ar); });
        }
コード例 #7
0
        public void AsyncBlockUntilComplete()
        {
            String expectedResult          = "Result we expected";
            AsynchronousTask <String> task = new AsynchronousTask <String>(expectedResult, 1);
            IAsyncResult ar = task.BeginDoTask(null, this);

            Stopwatch timer        = Stopwatch.StartNew();
            String    actualResult = task.EndDoTask(ar);

            timer.Stop();

            Assert.True(ar.IsCompleted);
            Assert.False(ar.CompletedSynchronously);
            Assert.Same(expectedResult, actualResult);
            Assert.True(timer.ElapsedMilliseconds > 500L);
        }
コード例 #8
0
        public void AsyncCallBackNotification()
        {
            CallBackHelper callBackRecorder = new CallBackHelper();
            String expectedResult = "Result we expected";
            AsynchronousTask<String> task = new AsynchronousTask<String>(expectedResult, 1);

            IAsyncResult ar = task.BeginDoTask(callBackRecorder.CallBack, this);
            Thread.Sleep(2000);

            Assert.Same(ar, callBackRecorder.Result);
            Assert.True(ar.IsCompleted);
            Assert.False(ar.CompletedSynchronously);
            
            String actualResult = task.EndDoTask(ar);  // should not throw
            Assert.Same(expectedResult, actualResult);
        }
コード例 #9
0
        public void AsyncPollingNotificationWithException()
        {
            InvalidOperationException terminatingException = new InvalidOperationException("Failure succeeded");
            AsynchronousTask          task = new AsynchronousTask(1, terminatingException);

            IAsyncResult ar = task.BeginDoTask(null, this);

            while (!ar.IsCompleted)
            {
                Thread.Sleep(500);
            }

            Assert.True(ar.IsCompleted);
            Assert.False(ar.CompletedSynchronously);

            Assert.Throws <InvalidOperationException>(delegate { task.EndDoTask(ar); });
        }
コード例 #10
0
        public void AsyncCallBackNotification()
        {
            CallBackHelper            callBackRecorder = new CallBackHelper();
            String                    expectedResult   = "Result we expected";
            AsynchronousTask <String> task             = new AsynchronousTask <String>(expectedResult, 1);

            IAsyncResult ar = task.BeginDoTask(callBackRecorder.CallBack, this);

            Thread.Sleep(2000);

            Assert.Same(ar, callBackRecorder.Result);
            Assert.True(ar.IsCompleted);
            Assert.False(ar.CompletedSynchronously);

            String actualResult = task.EndDoTask(ar);  // should not throw

            Assert.Same(expectedResult, actualResult);
        }
コード例 #11
0
        public void AsyncPollingNotification()
        {
            AsynchronousTask task = new AsynchronousTask(1);

            IAsyncResult ar = task.BeginDoTask(null, this);

            Int32 count = 0;

            while (!ar.IsCompleted)
            {
                count++;
                Thread.Sleep(500);
            }

            Assert.True(count > 0);
            Assert.True(ar.IsCompleted);
            Assert.False(ar.CompletedSynchronously);

            task.EndDoTask(ar);  // should not throw
        }
コード例 #12
0
        public void AsyncPollingNotification()
        {
            String expectedResult = "Result we expected";
            AsynchronousTask<String> task = new AsynchronousTask<String>(expectedResult, 1);

            IAsyncResult ar = task.BeginDoTask(null, this);

            Int32 count = 0;
            while (!ar.IsCompleted)
            {
                count++;
                Thread.Sleep(500);
            }

            Assert.True(count > 0);
            Assert.True(ar.IsCompleted);
            Assert.False(ar.CompletedSynchronously);

            String actualResult = task.EndDoTask(ar);  // should not throw
            Assert.Same(expectedResult, actualResult);
        }
コード例 #13
0
        public void AsyncPollingNotification()
        {
            String expectedResult          = "Result we expected";
            AsynchronousTask <String> task = new AsynchronousTask <String>(expectedResult, 1);

            IAsyncResult ar = task.BeginDoTask(null, this);

            Int32 count = 0;

            while (!ar.IsCompleted)
            {
                count++;
                Thread.Sleep(500);
            }

            Assert.True(count > 0);
            Assert.True(ar.IsCompleted);
            Assert.False(ar.CompletedSynchronously);

            String actualResult = task.EndDoTask(ar);  // should not throw

            Assert.Same(expectedResult, actualResult);
        }
コード例 #14
0
        public void AsyncPollingNotification()
        {
            AsynchronousTask task = new AsynchronousTask(1);

            IAsyncResult ar = task.BeginDoTask(null, this);

            Int32 count = 0;
            while (!ar.IsCompleted)
            {
                count++;
                Thread.Sleep(500);
            }

            Assert.True(count > 0);
            Assert.True(ar.IsCompleted);
            Assert.False(ar.CompletedSynchronously);

            task.EndDoTask(ar);  // should not throw
        }
コード例 #15
0
        public void AsyncPollingNotificationWithException()
        {
            InvalidOperationException terminatingException = new InvalidOperationException("Failure succeeded");
            AsynchronousTask<String> task = new AsynchronousTask<String>(1, terminatingException);

            IAsyncResult ar = task.BeginDoTask(null, this);

            while (!ar.IsCompleted)
            {
                Thread.Sleep(500);
            }

            Assert.True(ar.IsCompleted);
            Assert.False(ar.CompletedSynchronously);

            Assert.Throws<InvalidOperationException>(delegate { task.EndDoTask(ar); });
        }
コード例 #16
0
        public void AsyncBlockUntilCompleteWithException()
        {
            InvalidOperationException terminatingException = new InvalidOperationException("Failure succeeded");
            AsynchronousTask<String> task = new AsynchronousTask<String>(1, terminatingException);
            IAsyncResult ar = task.BeginDoTask(null, this);

            Assert.Throws<InvalidOperationException>(delegate { task.EndDoTask(ar); });
        }
コード例 #17
0
        public void AsyncBlockUntilComplete()
        {
            String expectedResult = "Result we expected";
            AsynchronousTask<String> task = new AsynchronousTask<String>(expectedResult, 1);
            IAsyncResult ar = task.BeginDoTask(null, this);

            Stopwatch timer = Stopwatch.StartNew();
            String actualResult = task.EndDoTask(ar);
            timer.Stop();

            Assert.True(ar.IsCompleted);
            Assert.False(ar.CompletedSynchronously);
            Assert.Same(expectedResult, actualResult);
            Assert.True(timer.ElapsedMilliseconds > 500L);
        }
コード例 #18
0
        public void AsyncBlockUntilComplete()
        {
            AsynchronousTask task = new AsynchronousTask(1);
            IAsyncResult ar = task.BeginDoTask(null, this);

            Stopwatch timer = Stopwatch.StartNew();
            task.EndDoTask(ar);
            timer.Stop();

            Assert.True(ar.IsCompleted);
            Assert.False(ar.CompletedSynchronously);
            Assert.True(timer.ElapsedMilliseconds > 500L);
        }