只要使用到两个类一个用来发送一个用来接收。可以有多个发送端,但只能有一个接收端。
来段demo
public partial class localcoon : UserControl {
public localcoon() {
InitializeComponent();
//
_sender = new LocalMessageSender("InAction", LocalMessageSender.Global);
textBox1.TextChanged += (s, e) => {
&nb上海闵行企业网站制作sp; {
_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: " +上海网站建设span> e.ReceiverName + Environment.NewLine +
//获取此发送方会将消息发送到的 LocalMessageReceiver 的名称。
"SenderDomain: " + e.SenderDomain;//获取此发送方会将消息发送到的 LocalMessageReceiver 的域
};
}
}
其中一个是IE9 一个是 opera浏览器。一些模糊的概念1域。详见扩展阅读
“域(Domain)”和“应用程序域(AppDomain)”不是一回事。域表明了Silverlight应用程序的位置信息,诸如:“www.myuniversity.edu.cn”之类,而应用程序域则代表了Silverlight应用程序的运行环境,Silverlight插件在装载一个Silverlight应用程序时,会为其创建一个应用程序域作为其运行环境。
假设某网页使用多个<object>元素承载了多个Silverlight应用程序,则Silverlight插件会为每个Silverlight应用程序创建相互独立的应用程序域,这些Silverlight应用程序的“域”可以相同(只要来源于同一个网站),也可以不同(如果来源于不同的网站)
自定义的时候可以是
Receiver = new LocalMessageReceiver("InAction",
ReceiverNameScope.Global,
new string[] {"www.baidu.com",www.xxx.com});
如果想指定任意可以是
其最终是调用下面函数发送的
[DllImport("agcore", EntryPoint="LocalMessageSend")]
private static extern uint LocalMessageSendNative
(IntPtr nativePeerPtr, uint cMessage, [MarshalAs(UnmanagedType.LPWStr)] string message,
uint cReceiverName, [MarshalAs(UnmanagedType.LPWStr)] string receiverName,
uint cReceiverDomain, [MarshalAs(UnmanagedType.LPWStr)] string receiverDomain, uint manag上海闵行企业网站设计与制作edKey);