Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 494109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:28:02+00:00 2026-05-13T05:28:02+00:00

I am currently having an issue of losing a message. This error occurs rarely,

  • 0

I am currently having an issue of losing a message. This error occurs rarely, but happens often enough to be annoying. Here is the context of the issue:

  • I have turned on the message journal on goldmine_service_queue, a MSMQ on Windows 2003 server.
  • I can prove that the message is being inserted into goldmine_service_queue since the message appears in the message journal. This information gives timing information about when the message disappeared.
  • The logging functions use http://logging.apache.org/log4net/index.html
  • The logs do not show errors.
  • The worker function(shown below) executes within a thread of a Windows service. It is responsible for peeking at messages(work items) from the queue and processing them.
  • From the logs, I strongly suspect that my issue might relate to MessageQueue.Peek and time out behavior.

Is it possible for the timeout and message receive to occur at the same time? Is there a better way for me to handle service stop checking to help avoid this error?

        private void workerFunction()
    {

        logger.Info("Connecting to queue: " + Settings.Default.goldmine_service_queue);
        MessageQueue q = new MessageQueue(Settings.Default.goldmine_service_queue);
        q.Formatter = new ActiveXMessageFormatter();

        while (serviceStarted)
        {

            Message currentMessage = null;

            try
            {
                currentMessage = q.Peek(new TimeSpan(0,0,30));
            }
            catch (System.Messaging.MessageQueueException mqEx)
            {
                if (mqEx.ToString().Contains("Timeout for the requested operation has expired"))
                {
                    logger.Info("Check for service stop request");
                }
                else
                {
                    logger.Error("Exception while peeking into MSMQ: " + mqEx.ToString());
                }
            }
            catch (Exception e)
            {
                logger.Error("Exception while peeking into MSMQ: " + e.ToString());
            }

            if (currentMessage != null)
            {

                logger.Info(currentMessage.Body.ToString());
                try
                {
                    ProcessMessage(currentMessage);
                }
                catch (Exception processMessageException)
                {
                    logger.Error("Error in process message: " + processMessageException.ToString());
                }

                //Remove message from queue.
                logger.Info("Message removed from queue.");
                q.Receive();
                //logPerformance(ref transCount, ref startTime);
            }


        }//end while

        Thread.CurrentThread.Abort();

    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T05:28:02+00:00Added an answer on May 13, 2026 at 5:28 am

    I don’t think any messages should be missed based on a quick review, but you are working in a very odd way with lots of scope for race conditions.

    Why not just receive the message and pass it to ProcessMessage (if ProcessMessage fails, you are performing a read anyway). If you need to handle multiple receivers, then do the receive in an MSMQ transaction so the message is unavailable to other receivers but not removed from the queue until the transaction is committed.

    Also, rather than polling the queue, why not do an asynchronous receive and let the thread pool handle the completion (where you must call EndReceive). This saves tying up a thread, and you don’t need to special case service shutdown (close the message queue and then call MessageQueue.ClearConnectionCache();).

    Also, aborting the thread is a really bad way to exit, just return from the thread’s start function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I hope someone here can help me.. I am currently having a small issue
I'm currently using this jQuery validate plugin and having an issue in IE where
I am setting a cookie, but having some issue. Currently the cookie format is
Currently having an issue with this test windows form application. The constructor works to
I am currently having an issue with my Web site 'title'. This is currently
I am currently having an issue with BackgroundWorker running on Windows Server 2003. I
I'm currently having an issue wrapping my brain around the notion of converting my
I'm currently having an issue storing mouse coordinates into an array in which a
Hi All I am currently having an issue calling a WCF service from a
I'm having an issue with multiple markers on google maps - I currently have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.