我怀疑它是,但希望得到确认,最好来自权威来源。
我有一个线程(比如线程A)循环从MessageQueue中读取消息:
Message message = queue.Receive();
然后它将消息传递给另一个线程(比如线程B),然后循环以等待下一条消息。线程B通过访问Message.BodyStream属性来处理消息。
线程A(接收线程)偶尔会从Receive方法中获取异常。这些例外的例子有:
System.Messaging.MessageQueueException (0x80004005): Operation was cancelled before it could be completed.
at System.Messaging.MessageQueue.ReceiveCurrent(TimeSpan timeout, Int32 action, CursorHandle cursor, MessagePropertyFilter filter, MessageQueueTransaction internalTransaction, MessageQueueTransactionType transactionType)
at System.Messaging.MessageQueue.Receive()
和
System.Messaging.MessageQueueException (0x80004005)
at System.Messaging.MessageQueue.MQCacheableInfo.get_ReadHandle()
at System.Messaging.MessageQueue.StaleSafeReceiveMessage(UInt32 timeout, Int32 action, MQPROPS properties, NativeOverlapped* overlapped, ReceiveCallback receiveCallback, CursorHandle cursorHandle, IntPtr transaction)
at System.Messaging.MessageQueue.ReceiveCurrent(TimeSpan timeout, Int32 action, CursorHandle cursor, MessagePropertyFilter filter, MessageQueueTransaction internalTransaction, MessageQueueTransactionType transactionType)
at System.Messaging.MessageQueue.Receive()
发生这种情况时,线程A(接收线程)关闭并重新创建队列,然后再继续。
我的问题是:
在不同的线程上访问Message.BodyStream通常是线程安全的吗?
如果队列被线程A关闭并重新创建,而线程B正在处理消息并访问Message.BodyStream,是否会导致问题?
关闭并重新创建队列时,适当的错误恢复策略是MessageQueue.Receive是否会抛出MessageQueueException?
关于为何可能发生这些例外的任何线索的奖励积分。