Exemplo n.º 1
0
        public void TestChannelSendOverloads()
        {
            using (IpcEventChannel sender = new IpcEventChannel(_registrar, _channel))
            using (IpcEventChannel ch1 = new IpcEventChannel(_registrar, _channel))
            using (IpcEventChannel ch2 = new IpcEventChannel(_registrar, _channel))
            {
                ch1.StartListening("ch1");
                ch2.StartListening("ch2");

                int ch1Count = 0, ch2Count = 0;
                ch1["Message"].OnEvent += delegate(object o, IpcSignalEventArgs e) { ch1Count++; };
                ch2["Message"].OnEvent += delegate(object o, IpcSignalEventArgs e) { ch2Count++; };

                sender.ExecutionTimeout = 1000;
                Assert.AreEqual(1, sender.SendTo("CH1", "Message"));
                Assert.AreEqual(1, sender.SendTo(new string[] { "CH2" }, "Message"));
                Assert.AreEqual(2, sender.SendTo(1000, new string[] { "ch1", "ch2" }, "Message"));

                ch1.StopListening();
                Assert.AreEqual(2, ch1Count);
                ch2.StopListening();
                Assert.AreEqual(2, ch2Count);
            }
        }
Exemplo n.º 2
0
        public void TestChannelNamedInstance()
        {
            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.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++; };

                for (int i = 0; i < 1000; i++)
                    Assert.AreEqual(1, sender.SendTo(10000, i % 2 == 0 ? "ch1" : "ch2", "Test"));

                sender.StopAsyncSending(true, -1);
                ch1.StopListening();
                ch2.StopListening();
            }
            Assert.AreEqual(500, ch1count);
            Assert.AreEqual(500, ch2count);
        }