LocalMessageSender Class
Represents the sending end of a local messaging channel between two Silverlight-based applications.
Namespace: System.Windows.Messaging
Assembly: System.Windows (in System.Windows.dll)
The LocalMessageSender type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | LocalMessageSender(String) | Initializes a new instance of the LocalMessageSender class and configures it to send messages to the receiver with the specified name. |
![]() | LocalMessageSender(String, String) | Initializes a new instance of the LocalMessageSender class and configures it to send messages to the receiver with the specified name and domain. |
| Name | Description | |
|---|---|---|
![]() | ReceiverDomain | Gets the domain of the LocalMessageReceiver that this sender will send messages to. |
![]() | ReceiverName | Gets the name of the LocalMessageReceiver that this sender will send messages to. |
| Name | Description | |
|---|---|---|
![]() | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | SendAsync(String) | Sends the specified message to the configured receiver asynchronously. |
![]() | SendAsync(String, Object) | Sends the specified messages to the configured receiver asynchronously. |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
A LocalMessageSender object can send messages to a LocalMessageReceiver object in a different Silverlight-based application running on the same computer. For information about using these classes, see Communication Between Local Silverlight-Based Applications.
The following code example demonstrates how to use this class. This example is part of a larger example available in How to: Implement Communication Between Local Silverlight-Based Applications.
Imports System Imports System.Windows Imports System.Windows.Controls Imports System.Windows.Messaging Partial Public Class Sender Inherits UserControl Private messageSender As LocalMessageSender Public Sub New() InitializeComponent() UpdateButton() messageSender = New LocalMessageSender( _ "receiver", LocalMessageSender.Global) AddHandler messageSender.SendCompleted, _ AddressOf sender_SendCompleted SendMessage("message from Sender constructor") End Sub Private clickNumber As Integer = 1 Private Sub UpdateButton() button.Content = "send message 'click " & clickNumber & "'" End Sub Private Sub Button_Click(ByVal sender As Object, _ ByVal e As RoutedEventArgs) SendMessage("click " & clickNumber) clickNumber += 1 UpdateButton() End Sub Private Const MAX_ATTEMPTS As Integer = 10000 Private attempt As Integer = 1 Private Sub SendMessage(ByVal message As String) messageSender.SendAsync(message, attempt) End Sub Private Sub sender_SendCompleted(ByVal sender As Object, _ ByVal e As SendCompletedEventArgs) If e.Error IsNot Nothing Then LogError(e) attempt += 1 If attempt > MAX_ATTEMPTS Then output.Text = "Could not send message." Return End If SendMessage(e.Message) Return End If output.Text = _ "Message: " & e.Message & Environment.NewLine & _ "Attempt " & CType(e.UserState, Integer) & _ " completed." & Environment.NewLine & _ "Response: " & e.Response & Environment.NewLine & _ "ReceiverName: " & e.ReceiverName & Environment.NewLine & _ "ReceiverDomain: " & e.ReceiverDomain ' Reset attempt counter. attempt = 1 End Sub Private Sub LogError(ByVal e As SendCompletedEventArgs) System.Diagnostics.Debug.WriteLine( _ "Attempt number {0}: {1}: {2}", CType(e.UserState, Integer), _ e.Error.GetType().ToString(), e.Error.Message) End Sub End Class
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.
