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

  • SEARCH
  • Home
  • 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 8361283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:39:48+00:00 2026-06-09T11:39:48+00:00

I have a message queue where i add some emails. I want to extract

  • 0

I have a message queue where i add some emails.
I want to extract all emails, examine the date when they were added and their priority and send only one of them.
I read messages like this:

private IList<Email> GetEmailsFromQueue(MessageQueue queue)
{
    queue.Formatter = new XmlMessageFormatter(new Type[] { typeof(Email) });
    IList<Email> emails = new List<Email>();
    Cursor cursor = queue.CreateCursor();
    Message m = PeekWithoutTimeout(queue, cursor, PeekAction.Current);
    if (m != null)
    {
        emails.Add((Email)m.Body);
        while ((m = PeekWithoutTimeout(queue, cursor, PeekAction.Next)) != null)
        {
            emails.Add((Email)m.Body);
        }
    }
    return emails;
}

private Message PeekWithoutTimeout(MessageQueue q, Cursor cursor, PeekAction action)
{            
    Message msgFromQueue = null;
    try
    {
        msgFromQueue = q.Peek(new TimeSpan(1), cursor, action);
    }
    catch(MessageQueueException ex)
    {
        if (!ex.Message.ToLower().Contains("timeout"))
        {
            throw;
        }
    }
    return msgFromQueue;
}

Receive method will remove the message from the queue.
Is there any way to read and remove only some messages?

LE: One solution i mighty think of is to add an id to each message, and use ReceiveById

Any other tips?

  • 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-06-09T11:39:49+00:00Added an answer on June 9, 2026 at 11:39 am

    Is there any way to read and remove only some messages?

    I’ve never used MSMQ (well not in anger anyways) but I think you should be able to combine both the Peek and ReceiveById methods.

    So you would continue to Peek at the queue to see what messages are available and then once you have decided to remove a message make use of the ReceiveById, to process/remove from the queue.

    Aside from this perhaps the other option would be to make use of 2 queues. The first would be for all inbound messages and the second would be used to add back messages you want to keep.

    So going back to your example (assuming I understand what you’re trying to achieve)

    • the first would be for inbound emails which you process as described extract all emails, examine the date when they were added and their priority
    • the second would be for your outbound emails i.e. once you have the email you want to send, push it on to the outbound queue
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web service , i add some extra class which have message
I my framework I have some functions that when done they can add some
Here I have to send and receive dynamic data using a SysV message queue.
I have a message handler, which consumes from a JMS queue and that sends
I have a queue of text messages in Redis. Let's say a message in
First of all, I'm new to ZeroMQ and message queue systems, so what I'm
I have a windows service that serves messages of some virtual queue via a
I have some services which i want to be able to publish and subscribe
in a C++ program I have graphs to which I'd like to add some
I have one thread that add() s objects into a LinkedList queue, and another

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.