0

LocalMessageReceiverおよびクラスを使用して、LocalMessageSender2 つの 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;
    }
}
4

1 に答える 1

0

これはあなたが望むものかもしれません...

messageReceiver.MessageReceived += (s, e) => 
    Task.Factory.StartNew(() => MessageReceiver_MessageReceived(s, e));

またはスレッドを使用する...new Thread(() => MessageReceiver_MessageReceived(s, e)).Start();

于 2012-04-13T22:35:26.350 に答える