示例#1
0
        public void Create_disposeInOtherThread_error()
        {
            Exception error = null;
            StaComCrossThreadInvoker sut = null;
            var t1 = new Thread(() =>
            {
                sut = new StaComCrossThreadInvoker();
            });

            t1.SetApartmentState(ApartmentState.STA);
            t1.Start();
            t1.Join();

            var t2 = new Thread(() =>
            {
                try
                {
                    sut.Dispose();
                }
                catch (Exception ex)
                {
                    error = ex;
                }
            });

            t2.SetApartmentState(ApartmentState.STA);
            t2.Start();
            t2.Join();

            Assert.IsInstanceOf <InvalidOperationException>(error);
        }
示例#2
0
        public void CreateAndDispose_smallMaximumTotalWaitTimeAndVeryBusyComServer_Canceled()
        {
            var thread = new Thread(() =>
            {
                using (var invoker = new StaComCrossThreadInvoker(1000))
                {
                    FakeComServer.RetryRejectedCall(invoker, 1001);
                    // if really call to COM object here - could throw exceptions
                }
            });

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            thread.Join();
            Assert.AreEqual(StaComCrossThreadInvoker.CANCEL, FakeComServer.LastRetryResult);
        }
        public void Create_disposeInOtherThread_error()
        {
            Exception error = null;
            StaComCrossThreadInvoker sut = null;
            var t1 = new Thread(() =>
            {
                sut = new StaComCrossThreadInvoker();
            });
            t1.SetApartmentState(ApartmentState.STA);
            t1.Start();
            t1.Join();

            var t2 = new Thread(() =>
            {
                try
                {
                    sut.Dispose();
                }
                catch (Exception ex)
                {
                    error = ex;
                }
            });
            t2.SetApartmentState(ApartmentState.STA);
            t2.Start();
            t2.Join();

            Assert.IsInstanceOf<InvalidOperationException>(error);
        }
 public void CreateAndDispose_smallMaximumTotalWaitTimeAndVeryBusyComServer_Canceled()
 {
     var thread = new Thread(() =>
     {
         using (var invoker = new StaComCrossThreadInvoker(1000))
         {
             FakeComServer.RetryRejectedCall(invoker, 1001);
             // if really call to COM object here - could throw exceptions
         }
     });
     thread.SetApartmentState(ApartmentState.STA);
     thread.Start();
     thread.Join();
     Assert.AreEqual(StaComCrossThreadInvoker.CANCEL, FakeComServer.LastRetryResult);
 }