共用方式為


LocalMessageReceiver Constructor (String)

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

Initializes a new instance of the LocalMessageReceiver class and configures it with the specified name.

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

Syntax

'Declaration
Public Sub New ( _
    receiverName As String _
)
public LocalMessageReceiver(
    string receiverName
)

Parameters

Exceptions

Exception Condition
ArgumentNullException

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

ArgumentException

receiverName is longer than 256 characters.

Remarks

This constructor initializes the ReceiverName property to the specified value, and the NameScope property to Domain. The AllowedSenderDomains property remains nulla null reference (Nothing in Visual Basic), which indicates that the receiver can receive messages only from senders on the same domain.

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

Examples

The following code example demonstrates how to use this constructor.

' In the receiving application:
Dim messageReceiver As New LocalMessageReceiver("receiver")
AddHandler messageReceiver.MessageReceived, _
    AddressOf receiver_MessageReceived

Try

    messageReceiver.Listen()

Catch ex As ListenFailedException

    MessageBox.Show( _
        "Cannot receive messages." & Environment.NewLine & _
        "There is already a receiver with the name 'receiver'.", _
        "LocalMessageReceiver", MessageBoxButton.OK)

End Try

' In the sending application:
Dim messageSender As New LocalMessageSender("receiver")
AddHandler messageSender.SendCompleted, _
    AddressOf sender_SendCompleted
// In the receiving application:
LocalMessageReceiver messageReceiver = new LocalMessageReceiver("receiver");
messageReceiver.MessageReceived += new 
    EventHandler<MessageReceivedEventArgs>(receiver_MessageReceived);
try
{
    messageReceiver.Listen();
}
catch (ListenFailedException)
{
    MessageBox.Show(
        "Cannot receive messages." + Environment.NewLine +
        "There is already a receiver with the name 'receiver'.",
        "LocalMessageReceiver", MessageBoxButton.OK);
}

// In the sending application:
LocalMessageSender messageSender = new LocalMessageSender("receiver");
messageSender.SendCompleted += new 
    EventHandler<SendCompletedEventArgs>(sender_SendCompleted);

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.