LocalMessageReceiver
およびクラスを使用して、LocalMessageSender
2 つの Silverlight アプリケーション (1 つはブラウザー内、もう 1 つはブラウザー外) 間で通信しています。messageReceiver.MessageReceived
新しいスレッドで実行する必要があります。これは私の基本コードです:
public MainPage()
{
LocalMessageReceiver messageReceiver = new LocalMessageReceiver("Msg", ReceiverNameScope.Global, LocalMessageReceiver.AnyDomain);
messageReceiver.MessageReceived += MessageReceiver_MessageReceived; //I want to execute this in a new Thread.
messageReceiver.DisableSenderTrustCheck = true;
try
{
messageReceiver.Listen();
}
catch (ListenFailedException)
{
//to do
}
}
private void MessageReceiver_MessageReceived(object sender, MessageReceivedEventArgs e)
{
string command = e.Message;
switch (command)
{
case "SCAN":
e.Response = Scan(e.Message); //I need to send a response
break;
default:
e.Response = "NULL";
break;
}
}