I have an application that has five threads. All five threads write to the
same MSMQ. All five threads are using the same global instance to send data
to the MSMQ server(on same machine).
Occasionally, I get the erroror below. The data(string) being sent is not
null or empty. Is this a problem related to multiple threads ? Right now I
have coded it like this
Controller.MSMQ.Send(Record);
Should I change to
lock(Controller.MSMQ)
{
Controller.MSMQ.Send(Record);
}
Thanks.
Below is the actual error
Specified cast is not valid.
P R O P E R T I E S
------------------
Message: Specified cast is not valid.
InnerException:
TargetSite: MQPROPS Lock()
StackTrace: at System.Messaging.Interop.MessagePropertyVariants.L ock()
at System.Messaging.Message.Lock()
at System.Messaging.MessageQueue.SendInternal(Object obj,
MessageQueueTransaction internalTransaction, MessageQueueTransactionType
transactionType)
at System.Messaging.MessageQueue.Send(Object obj)
at TCPServer.CH.Process(String ThreadName)
HelpLink:
Source: System.Messaging