快捷搜索:

Silverlight杂记-本地程序间的互通<BR>来段demo<BR>如

只要应用到两个类一个用来发送一个用来接管。

可以有多个发送端,但只能有一个接管端。

来段demo

public partial class localcoon : UserControl {

public localcoon() {

InitializeComponent();

//

_sender = new LocalMessageSender("InAction", LocalMessageSender.Global);

textBox1.TextChanged += (s, e) => {

{

_sender.SendAsync(textBox1.Text);

}

};

}

private LocalMessageSender _sender;

private void button1_Click(object sender, RoutedEventArgs e1) {

//表示两个基于 Silverlight 的利用法度榜样之间的本地消息通报通道的接管端。

LocalMessageReceiver _receive;

_receive = new LocalMessageReceiver("InAction",

ReceiverNameScope.Global, LocalMessageReceiver.AnyDomain);

_receive.Listen();

_receive.MessageReceived += (s, e) => {

textBlock3.Text =

"Message: " + e.Message + Environment.NewLine +

"NameScope " + e.NameScope +

" completed." + Environment.NewLine +

"Response: " + e.Response + Environment.NewLine +

"ReceiverName: " + e.ReceiverName + Environment.NewLine +

//获取此发送方会将消息发送到的 LocalMessageReceiver 的名称。

"SenderDomain: " + e.SenderDomain;//获取此发送方会将消息发送到的 LocalMessageReceiver 的域

};

}

}

您可能还会对下面的文章感兴趣: