Actually, I have window service that read MSMQ queuw at an interval. My MSMQ queue is working without an issue but problem is when I stop or start windows service then it's throws an error. The complete error is given below:
**ERROR 65 DAL.MsmqImportListener - A MSMQ error occured
System.Messaging.MessageQueueException (0x80004005)
at System.Messaging.MessageQueue.AsynchronousRequest.End()
at DAL.MsmqImportListener.PeekCompleted(Object sender, PeekCompletedEventArgs e)**
private static void PeekCompleted(object sender, PeekCompletedEventArgs e)
{
var msmq = sender as MessageQueue;
var messageProcessor = e.AsyncResult.AsyncState as MessageProcessorMethod;
try
{
using (var scope = new TransactionScope())
{
msmq.EndPeek(e.AsyncResult);
var message = msmq.ReceiveById(
e.Message.Id,
TimeSpan.FromSeconds(double.Parse(ConfigurationManager.AppSettings["MsmqReceiveTimeout"])),
MessageQueueTransactionType.Automatic);
messageProcessor(message);
scope.Complete();
}
}
catch (MessageQueueException mqe)
{
// Check if timeout...no action if timeout, else log error
if (mqe.MessageQueueErrorCode != MessageQueueErrorCode.IOTimeout)
{
Logger.Error("A MSMQ error occured", mqe);
EmailDispatcher.SendInformationEmail("A MSMQ error occured" + Environment.NewLine + mqe);
}
}
catch (Exception ex)
{
Logger.Error(
string.Format(
CultureInfo.InvariantCulture,
"An unexpected error was encountered, message with id {0} was put in error queue: {1}",
e.Message.Id,
success),
ex);
}
finally
{
msmq.BeginPeek(TimeSpan.FromSeconds(double.Parse(ConfigurationManager.AppSettings["MsmqPeekTimeout"])), messageProcessor);
}
}