|
只要使用到兩個類一個用來發送一個用來接收。可以有多個發送端,但只能有一個接收端。
來段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雜記-本地程序間的互通,轉載需保留來源!
鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。