|
只要使用到两个类一个用来发送一个用来接收。可以有多个发送端,但只能有一个接收端。
来段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 的域
};
}
}
NET技术:Silverlight杂记-本地程序间的互通,转载需保留来源!
郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。