Exemple #1
0
        public void GetAndRunDispatcher_invokeAndShutdown_invocationInDispatcherDone()
        {
            //start custom Dispatcher for Windows Message Pump
            NRegFreeCom.IDispatcher disp = null;
            var created = new ManualResetEvent(false);
            var t       = new Thread(x =>
            {
                disp = NRegFreeCom.Dispatcher.CurrentDispatcher;
                created.Set();
                NRegFreeCom.Dispatcher.Run();
            });

            t.SetApartmentState(ApartmentState.STA);
            t.Start();
            created.WaitOne();

            // run custom Dispatcher
            int    threadId = -1;
            bool   wasAct   = false;
            Action act      = () =>
            {
                wasAct   = true;
                threadId = Thread.CurrentThread.ManagedThreadId;
            };

            disp.Invoke(act);
            disp.InvokeShutdown();

            // invocation in Dispatcher thread was done
            Assert.AreEqual(threadId, t.ManagedThreadId);
            Assert.That(wasAct, Is.True);
        }
Exemple #2
0
        public void RunShutdown()
        {
            NRegFreeCom.IDispatcher disp = null;
            var t = new Thread(x =>
            {
                disp = NRegFreeCom.Dispatcher.CurrentDispatcher;
                NRegFreeCom.Dispatcher.Run();
            });

            t.SetApartmentState(ApartmentState.STA);
            t.Start();
            bool waitRun = t.Join(TimeSpan.FromMilliseconds(200));

            Assert.False(disp.HasShutdownFinished);
            disp.InvokeShutdown();

            bool waitShutdown = t.Join(TimeSpan.FromMilliseconds(50));

            Assert.False(waitRun);
            Assert.True(disp.HasShutdownFinished);
            Assert.True(waitShutdown);
        }