CSharpTest.Net
OnEvent Event
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.IpcChannel Namespace > IpcEvent Class : OnEvent Event

Glossary Item Box

Allows you to subscribe or unsubscribe to the event

Syntax

Visual Basic (Declaration) 
Public Event OnEvent As EventHandler(Of IpcSignalEventArgs)
C# 
public event EventHandler<IpcSignalEventArgs> OnEvent

Event Data

The event handler receives an argument of type IpcSignalEventArgs containing data related to this event. The following IpcSignalEventArgs properties provide information specific to this event.

PropertyDescription
Arguments Gets any arguments sent with the event
EventChannel Gets the channel rasing the event
EventName Gets the name of the event

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