Domanda

Ho un problema quando la gestione dell'evento ReceiveCompleted di un MessageQueue in ASP.NET. Si afferra con successo, ma ogni modifica applicata ai controlli della pagina non hanno alcun effetto.

Questo è quello che ho:

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();
}

Non perché non riesce aggiornare quelli Vars. Può essere qualsiasi nonesense, ma io sono nuovo a ASP.NET, in modo che qualsiasi indizio sarà il benvenuto.

Grazie in anticipo!

Pablo

È stato utile?

Soluzione

Si desidera che la pagina del cliente per essere aggiornato dal comando (causata da mq_ReceiveCompleted) dal server, giusto? E non è possibile se è così.

Il mio suggerimento è quello di mettere una funzione JS client che verrà chiamato da timer (ogni secondo o giù di lì) e invierà una richiesta asincrona AJAX per il servizio web per i nuovi messaggi in MessageQueue. Se esiste tale messaggio il JS prenderà tutte le azioni necessarie (aggiornamento della pagina, ecc.)

Altri suggerimenti

provare a impostare il UpdateMode = "always" per la vostra UpdatePanel, o UpdatePanel1.Update(); chiamata alla fine del mq_ReceiveCompleted () metodo.

Controlla che si sta aggiornando la corretta istanza dell'oggetto pagina.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top