MessageReceived Event
Collapse the table of content
Expand the table of content

LocalMessageReceiver.MessageReceived Event


Occurs when a message is received from a LocalMessageSender.

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

public event EventHandler<MessageReceivedEventArgs> MessageReceived

This event will not occur until after you have called the Listen method.

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

The following code example demonstrates how to use this event. This example is part of a larger example available in How to: Implement Communication Between Local Silverlight-Based Applications.

using System;
using System.Windows.Controls;
using System.Windows.Messaging;

namespace ReceivingApplication
    public partial class Receiver : UserControl
        public Receiver()

            LocalMessageReceiver messageReceiver =
                new LocalMessageReceiver("receiver",
                ReceiverNameScope.Global, LocalMessageReceiver.AnyDomain);
            messageReceiver.MessageReceived += messageReceiver_MessageReceived;
            catch (ListenFailedException)
                output.Text = "Cannot receive messages." + Environment.NewLine +
                    "There is already a receiver with the name 'receiver'.";

        private void messageReceiver_MessageReceived(
            object sender, MessageReceivedEventArgs e)
            e.Response = "response to " + e.Message;
            output.Text =
                "Message: " + e.Message + Environment.NewLine +
                "NameScope: " + e.NameScope + Environment.NewLine +
                "ReceiverName: " + e.ReceiverName + Environment.NewLine +
                "SenderDomain: " + e.SenderDomain + Environment.NewLine +
                "Response: " + e.Response;


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

© 2016 Microsoft