我有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
我无法弄清楚plz帮助我的问题
我的应用程序下面有简短的代码示例。
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);
}
}
}
}
答案 0 :(得分:0)
通过在app config中添加此跟踪来启用跟踪日志记录:
<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>
你可能需要稍微调整设置以使其工作,但它主要在那里 这有助于正确诊断错误。