Allows you to subscribe or unsubscribe to the event
Syntax
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.
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.NET | Copy 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