我正在使用LocalMessageReceiver
andLocalMessageSender
类在两个 Silverlight 应用程序之间进行通信(一个在浏览器中,另一个在浏览器外)。我需要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;
}
}