LocalMessageSender.SendAsync Method (String)

Silverlight

Sends the specified message to the configured receiver asynchronously.

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

public void SendAsync(
	string message
)

Parameters

message
Type: System.String
The message to send.

ExceptionCondition
ArgumentNullException

message is null.

ArgumentException

message is longer than 40,960 characters.

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.

The following code example demonstrates how to use this method.


// 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);
}


Silverlight

Supported in: 5, 4, 3

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

Community Additions

ADD
Show: