示例#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);
        }
        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
        }
        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); });
        }
        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);
        }
        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); });
        }
        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
        }
        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);
        }
        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
        }
        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); });
        }
        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); });
        }
        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);
        }