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

Glossary Item Box

Enables a background worker thread to continue sending messages that are incomplete after the expiration of the timeout specified in the Broadcast/SendTo method. This is required to avoid dead-locks if your broadcasting messages within an IpcEvent.OnEvent event handler.

Syntax

Visual Basic (Declaration) 
Public Sub EnableAsyncSend() 
C# 
public void EnableAsyncSend()

Example

Library/Library.Test/TestIpcChannel.cs

C#Copy Code
using (IpcEventChannel ch1 = new IpcEventChannel(_registrar, _channel))
using (IpcEventChannel sender = new IpcEventChannel(_registrar, _channel))
{
    ch1.StartListening("ch1");

    ManualResetEvent ready = new ManualResetEvent(false);
    ManualResetEvent die = new ManualResetEvent(false);
    ch1["Message"].OnEvent += delegate(object o, IpcSignalEventArgs e)
    {
        ready.Set();
        die.WaitOne();
        Thread.CurrentThread.Abort();
    };

    sender.Broadcast(100, "Message");
    Assert.IsTrue(ready.WaitOne(1000, false));

    sender.EnableAsyncSend();
    sender.Broadcast(0, "Message");
    die.Set();
    sender.StopAsyncSending(true, 1000);
    ch1.StopListening();
}
VB.NETCopy Code
Using ch1 As New IpcEventChannel(_registrar, _channel)
    Using sender As New IpcEventChannel(_registrar, _channel)
        ch1.StartListening("ch1")

        Dim ready As New ManualResetEvent(False)
        Dim die As New ManualResetEvent(False)
        ch1("Message").OnEvent += Function(o As Object, e As IpcSignalEventArgs) Do
            ready.[Set]()
            die.WaitOne()
            Thread.CurrentThread.Abort()
        End Function

        sender.Broadcast(100, "Message")
        Assert.IsTrue(ready.WaitOne(1000, False))

        sender.EnableAsyncSend()
        sender.Broadcast(0, "Message")
        die.[Set]()
        sender.StopAsyncSending(True, 1000)
        ch1.StopListening()
    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