Microsoft消息队列
本文关键字:队列 消息 Microsoft | 更新日期: 2023-09-27 18:34:45
我有Windows应用程序。应用程序从 MS 读取消息消息队列。应用程序中的问题是有时不从消息队列中读取消息并抛出此异常。
Thread was being aborted.
at System.Messaging.Interop.UnsafeNativeMethods.MQReceiveMessage(MessageQueueHandle handle, UInt32 timeout, Int32 action, MQPROPS properties, NativeOverlapped* overlapped, ReceiveCallback receiveCallback, CursorHandle cursorHandle, IntPtr transaction)
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()
at Catalyst.CATS.DBService.OrdersQueueHandler.SynReceiveThreadMethod() in D:'svn'kinetic'Servers'Main DB Service'trunk'MainDatabaseServiceGUI'DBMainLogic'classes'OrdersQueueHandler.cs:line 143
我无法弄清楚问题请帮助我
我在下面有我的应用程序的简短代码示例。
public class Messages
{
private MessageQueue OrdersQueue;
OrdersQueue = MessageQueue.Create(".''Private$''DatabaseServerQueue", false);
OrdersQueue.SetPermissions("Everyone", System.Messaging.MessageQueueAccessRights.FullControl);
OrdersQueue.SetPermissions("ANONYMOUS LOGON", System.Messaging.MessageQueueAccessRights.FullControl);
OrdersQueue.UseJournalQueue = true;
public Messages()
{
thd = new Thread(new ThreadStart(SynReceiveThreadMethod));
thd.Start();
}
private void SynReceiveThreadMethod()
{
while(true)
{
try
{
Message dequeuedMessage = OrdersQueue.Receive();
}
catch (Exception ee)
{
System.Console.WriteLine(ee.Message);
System.Console.WriteLine(ee.StackTrace);
}
}
}
}
通过在应用程序配置中添加以下内容来启用跟踪日志记录:
<system.diagnostics>
<sources>
<source name="System.ServiceModel"
switchValue="Information, ActivityTracing"
propagateActivity="true" >
<listeners>
<add name="xml"/>
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging">
<listeners>
<add name="xml"/>
</listeners>
</source>
<source name="myUserTraceSource"
switchValue="Information, ActivityTracing">
<listeners>
<add name="xml"/>
</listeners>
</source>
</sources>
<sharedListeners>
<add name="xml"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData="C:'logs'Log.svclog" />
</sharedListeners>
</system.diagnostics>
您可能需要稍微调整设置才能使其正常工作,但它主要在那里这将有助于正确诊断错误。