Freigeben über


LocalMessageSender.SendAsync Method (String)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Sends the specified message to the configured receiver asynchronously.

Namespace:  System.Windows.Messaging
Assembly:  System.Windows (in System.Windows.dll)

Syntax

'Declaration
Public Sub SendAsync ( _
    message As String _
)
public void SendAsync(
    string message
)

Parameters

Exceptions

Exception Condition
ArgumentNullException

message is nulla null reference (Nothing in Visual Basic).

ArgumentException

message is longer than 40,960 characters.

Remarks

You can send messages up to 40 kilobytes long.

When you call this method, the MessageReceived event occurs for the LocalMessageReceiver that corresponds to the ReceiverName and ReceiverDomain settings. Then, the SendCompleted event occurs, regardless of whether the message was successfully sent.

For more information, see Communication Between Local Silverlight-Based Applications.

Examples

The following code example demonstrates how to use this method.

' In the sending application:
Private Sub SendMessage(ByVal messageSender As LocalMessageSender)

    MessageBox.Show("Sending message ""message"".", _
        "LocalMessageSender", MessageBoxButton.OK)
    messageSender.SendAsync("message")

End Sub

' In the receiving application:
Private Sub receiver_MessageReceived(ByVal sender As Object, _
    ByVal e As MessageReceivedEventArgs)

    MessageBox.Show("Message """ & e.Message & _
        """ received. Sending response ""response"".", _
        "LocalMessageReceiver", MessageBoxButton.OK)
    e.Response = "response"

End Sub

' In the sending application:
Private Sub sender_SendCompleted(ByVal sender As Object, _
    ByVal e As SendCompletedEventArgs)

    MessageBox.Show("Response """ & e.Response & """ receieved.", _
        "LocalMessageSender", MessageBoxButton.OK)

End Sub
// In the sending application:
private void SendMessage(LocalMessageSender messageSender)
{
    MessageBox.Show("Sending message \"message\".",
        "LocalMessageSender", MessageBoxButton.OK);
    messageSender.SendAsync("message");
}

// In the receiving application:
private void receiver_MessageReceived(object sender,
    MessageReceivedEventArgs e)
{
    MessageBox.Show("Message \"" + e.Message +
        "\" received. Sending response \"response\".",
        "LocalMessageReceiver", MessageBoxButton.OK);
    e.Response = "response";
}

// In the sending application:
private void sender_SendCompleted(object sender, 
    SendCompletedEventArgs e)
{
    MessageBox.Show("Response \"" + e.Response + "\" receieved.",
        "LocalMessageSender", MessageBoxButton.OK);
}

Version Information

Silverlight

Supported in: 5, 4, 3

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.