質問

ASP.NET で MessageQueue の ReceiveCompleted イベントを処理するときに問題が発生します。これは正常にキャッチされますが、ページのコントロールに適用されたすべての変更は効果がありません。

これが私が持っているものです:

.ASPX

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="False">
   <ContentTemplate>
       <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
       <br />
       <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
   </ContentTemplate>
</asp:UpdatePanel>

<asp:Timer ID="Timer1" runat="server" Interval="3000" ontick="Timer1_Tick">
</asp:Timer>

.CS

private static System.Messaging.MessageQueue queue;
private static String messageContent;

protected override void OnInit(EventArgs e)
{
    base.OnInit(e);
    queue = new MessageQueue(@".\Private$\MyQueue");
    queue.ReceiveCompleted += new ReceiveCompletedEventHandler(mq_ReceiveCompleted);
    queue.BeginReceive();
}


protected void mq_ReceiveCompleted(object sender, System.Messaging.ReceiveCompletedEventArgs e)
{

    System.Messaging.Message message = queue.EndReceive(e.AsyncResult);
    message.Formatter = new System.Messaging.XmlMessageFormatter(new string[] { "System.String,mscorlib" });

    Label1.Text = message.Body.ToString();      //Has no effect. The value updates without problem, but doesn't persist after finishing this method. And the Page doesn't refresh with this new value.
    Label2.Text = DateTime.Now.ToString();      //Has no effect too.
    Timer1.Interval = 99999;                    //And this one the same, no effect.
    messageContent = message.Body.ToString();   //.. But the value stored in this variable does persist

    queue.BeginReceive();
}

これらの変数の更新に失敗する理由がわかりません。ナンセンスかもしれませんが、私は ASP.NET を初めて使用するので、どんな手がかりでも歓迎します。

前もって感謝します!

パブロ

役に立ちましたか?

解決

あなたは、クライアントのページが右、サーバーから(mq_ReceiveCompletedによって引き起こされる)コマンドによって更新されるようにしたいですか?それはそうだ場合、それはできません。

私の提案は、タイマーによって呼び出されるクライアントJSの機能(各秒ほど)を置くことで、メッセージキューで新しいメッセージのためのWebサービスへの非同期AJAXリクエストを送信します。そのようなメッセージが存在する場合はJSは(など、ページを更新。)必要な行動をとるだろう。

他のヒント

を設定してみてください UpdateMode="常に" UpdatePanel に送信するか、呼び出します UpdatePanel1.Update(); の終わりに mq_ReceiveCompleted() 方法。

あなたがページオブジェクトの正しいインスタンスを更新していることを確認します。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top