I have messages that get stuck in queue and I am looking for a way to programmatically remove them.
Is there a way to remove messages from a queue if it has been sit
I think you can do something like this:
MessageQueue queue = new MessageQueue(@".\private$\SomeTestName");
var messages = queue.GetAllMessages();
var messagesToDelete = messages.Where(m => m.ArrivedTime < DateTime.Now.AddDays(-1)).ToList();
messagesToDelete.ForEach(m=>queue.ReceiveById(m.Id));
Obviously, you'll have to modify the date stuff to correspond with your scenario.