0

我有 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);
                }
        }
}
}
4

1 回答 1

0

通过在应用程序配置中添加以下内容来启用跟踪日志记录:

<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>

您可能需要稍微调整设置以使其正常工作,但它主要存在这将有助于正确诊断错误。

于 2013-10-10T05:09:26.027 回答