Good night guys!

I'm having the following problem ... I have a web application that runs a "thread" that takes messages from the queue (MSMQ) ... Everything works correctly .. the problem is when I get this message, I can not display .. because the method that returns the message content is a "static" .. I need to perform a function in JS to display this message.

conclusion: The method "ProcessMessage" can not be named because he is not a static method ... My main goal is to call a function in JS passing as parameter (m.Body.ToString ()) which is the content of the message.

Can anyone help me?

Thank you for sharing your knowledge!

This is my code.

    public void StartThread()
    {
        try
        {
            while (true)
            {
                PrepareQueue();
            }
        }
        catch (Exception)
        { }
    }

    public static void PrepareQueue()
    {
        MessageQueue myQueue = new MessageQueue(".\\private$\\CTIQueue");
        myQueue.Formatter = new XmlMessageFormatter(new Type[] { typeof(String) });

        // Add an event handler for the ReceiveCompleted event.
        myQueue.ReceiveCompleted += new ReceiveCompletedEventHandler(MyReceiveCompleted);

        // Define wait handles for multiple operations.
        WaitHandle[] waitHandleArray = new WaitHandle[10];
        for (int i = 0; i < 10; i++)
        {
            // Begin asynchronous operations.
            waitHandleArray[i] = myQueue.BeginReceive().AsyncWaitHandle;
        }

        // Specify to wait for all operations to return.
        WaitHandle.WaitAll(waitHandleArray);

        return;
    }

    private static void MyReceiveCompleted(Object source, ReceiveCompletedEventArgs asyncResult)
    {
        try
        {
            Thread.Sleep(2000);

            MessageQueue mq = (MessageQueue)source;

            // End the asynchronous receive operation.
            System.Messaging.Message m = mq.EndReceive(asyncResult.AsyncResult);
            ProcessMessage(m.Body.ToString()); <-- MY PROBLEM
        }
        catch (MessageQueueException)
        { }

        return;
    }

    public void ProcessMessage(string message)
    {
        ScriptManager.RegisterStartupScript(this, GetType(), "popup", "NewCaller('" + message + "');", true);
    }

Related posts

Recent Viewed