CSharpTest.Net
IpcEventChannel Constructor(IIpcChannelRegistrar,String)
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.IpcChannel Namespace > IpcEventChannel Class > IpcEventChannel Constructor : IpcEventChannel Constructor(IIpcChannelRegistrar,String)

registrar
The serialization provider for registration
channelName
The name of the channel to subscribe or send events to

Glossary Item Box

Creates an IpcEventChannel that persists state in IChannelRegistrar provided

Syntax

Visual Basic (Declaration) 
Public Function New( _
   ByVal registrar As IIpcChannelRegistrar, _
   ByVal channelName As String _
)
C# 
public IpcEventChannel( 
   IIpcChannelRegistrar registrar,
   string channelName
)

Parameters

registrar
The serialization provider for registration
channelName
The name of the channel to subscribe or send events to

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

Requirements

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

See Also

Generated with Document! X 2011 by Innovasys