CSharpTest.Net
IpcEventChannel Class
Members  Example  See Also  Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.IpcChannel Namespace : IpcEventChannel Class

Glossary Item Box

Provides a means to send and recieve events (optionally with arguments) across thread/process boundaries to a group of listeners of an event channel. Subscribe to desired events, call Start/StopListening, or just send events to other listeners on the same channel name. Provides the implmentation to send an event message to a group of instances

Object Model

IpcEventChannel ClassIpcEvent ClassIIpcChannelRegistrar Interface

Syntax

Visual Basic (Declaration) 
Public Class IpcEventChannel 
C# 
public class IpcEventChannel 

Example

Library/Library.Test/TestIpcChannel.cs

C#Copy Code
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);
}
VB.NETCopy Code
Using sender As New IpcEventChannel(_registrar, _channel)
    Using ch1 As New IpcEventChannel(_registrar, _channel)
        Using ch2 As New IpcEventChannel(_registrar, _channel)
            ch1.StartListening("ch1")
            ch2.StartListening("ch2")

            Dim ch1Count As Integer = 0, ch2Count As Integer = 0
            ch1("Message").OnEvent += Function(o As Object, e As IpcSignalEventArgs) Do
                System.Math.Max(System.Threading.Interlocked.Increment(ch1Count),ch1Count - 1)
            End Function
            ch2("Message").OnEvent += Function(o As Object, e As IpcSignalEventArgs) Do
                System.Math.Max(System.Threading.Interlocked.Increment(ch2Count),ch2Count - 1)
            End Function

            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)
        End Using
    End Using
End Using

Inheritance Hierarchy

System.Object
   CSharpTest.Net.IpcChannel.IpcEventChannel

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys