public void RunInUserInterfaceThread()
        {
            BackgroundThreadPublisher publisher = new BackgroundThreadPublisher();

            UISubscriber subscriber = new UISubscriber();

            topic.AddSubscription(subscriber, "TestEventHandler", item, ThreadOption.UserInterface);

            publisher.CanFireTopic.Set();
            Application.Run();

            Assert.AreEqual(Thread.CurrentThread.ManagedThreadId, subscriber.ManagedThreadId);
        }
        public void RunInUserInterfaceThreadWithNoSyncronizationContextCallsSubscriber()
        {
            BackgroundThreadPublisher publisher = new BackgroundThreadPublisher();

            SynchronizationContext context    = SynchronizationContext.Current;
            TestSubscriber         subscriber = new TestSubscriber();

            topic.AddSubscription(subscriber, "TestEventHandler", item, ThreadOption.UserInterface);

            publisher.CanFireTopic.Set();

            subscriber.HandlerCalledSignal.WaitOne();
            Assert.IsTrue(subscriber.TestEventHandlerCalled);
        }
        public void RunInUserInterfaceThreadExceptionsAreReported()
        {
            BackgroundThreadPublisher publisher = new BackgroundThreadPublisher();

            UISubscriber subscriber = new UISubscriber();

            topic.AddSubscription(subscriber, "FailingHandler", item, ThreadOption.UserInterface);

            publisher.CanFireTopic.Set();
            Application.Run();

            Thread.Sleep(500);
            Assert.IsNotNull(publisher.ThrownException);
        }