Esempio n. 1
0
 public void TestChannelStartStop()
 {
     using (IpcEventChannel channel = new IpcEventChannel(_registrar, _channel))
     {
         channel.StartListening();
         channel.StopListening();
         channel.StartListening();
         channel.StopListening();
     }
 }
Esempio n. 2
0
        public void TestBroadcastWithNonResponsive()
        {
            ManualResetEvent wait = new ManualResetEvent(false);
            int ch1count = 0, ch2count = 0;

            using (IpcEventChannel ch1 = new IpcEventChannel(_registrar, _channel))
                using (IpcEventChannel ch2 = new IpcEventChannel(_registrar, _channel))
                    using (IpcEventChannel sender = new IpcEventChannel(_registrar, _channel))
                    {
                        ch1.DefaultTimeout      = 100;
                        ch2.DefaultTimeout      = 100;
                        sender.ExecutionTimeout = 0;

                        ch1.StartListening("ch1");
                        ch2.StartListening("ch2");
                        sender.EnableAsyncSend();

                        ch1["Test"].OnEvent += delegate(object o, IpcSignalEventArgs e)
                        { ch1count++; };
                        ch2["Test"].OnEvent += delegate(object o, IpcSignalEventArgs e)
                        { ch2count++; wait.WaitOne(); };

                        sender.Broadcast(100, "Test");
                        sender.Broadcast(100, "Test");
                        sender.Broadcast(100, "Test");
                        sender.StopAsyncSending(false, 0);
                        ch1.StopListening();
                    }
            //We don't need to release the thread by wait.Set(), the thread was aborted by the
            //Dispose()... Had we called ch2.StopListening() instead, the program would hang.
            //thus to gracefully shutdown one calls StopListening()
            Assert.AreEqual(3, ch1count);
            Assert.AreEqual(1, ch2count);
        }
Esempio n. 3
0
        public void TestChannelSelfDispatch()
        {
            int count = 0;

            using (IpcEventChannel channel = new IpcEventChannel(_registrar, _channel))
            {
                channel.StartListening();
                channel["Test"].OnEvent += delegate(object o, IpcSignalEventArgs e)
                { count++; };

                channel.Broadcast("Test");
                channel.Broadcast("Test");
                channel.Broadcast("Test");
                channel.StopListening();
            }
            Assert.AreEqual(3, count);
        }
Esempio n. 4
0
        public void TestChannelAbortPending()
        {
            AutoResetEvent finish = new AutoResetEvent(false);
            AutoResetEvent done   = new AutoResetEvent(false);
            int            count  = 0;

            using (IpcEventChannel channel = new IpcEventChannel(_registrar, _channel))
            {
                channel.EnableAsyncSend();
                channel.StartListening();
                channel["Test"].OnEvent += delegate(object o, IpcSignalEventArgs e)
                { finish.WaitOne(); count++; done.Set(); };

                Assert.AreEqual(1, channel.Broadcast(10000, "Test"));
                Assert.AreEqual(0, channel.Broadcast(0, "Test"));
                finish.Set();
                done.WaitOne();
            }
            Assert.AreEqual(1, count);
        }