我有一个多用户计划应用程序,其中客户端将包含其更改的 msmq 消息发送到服务器应用程序,服务器应用程序处理它们,计算库存/时间短缺,然后向所有连接的客户端发送消息以更新其数据以显示更改。
这工作得很好,除了一个一直困扰着我的例外。
这基本上只发生在我们一些速度更快的 PC(带有 SSD、I7 等)上。
ExceptionInformation: System.Messaging.MessageQueueException
Stack:
at System.Messaging.MessageQueue+MQCacheableInfo.get_ReadHandle()
at System.Messaging.MessageQueue.StaleSafeReceiveMessage(UInt32, Int32, MQPROPS, System.Threading.NativeOverlapped*, ReceiveCallback, System.Messaging.Interop.CursorHandle, IntPtr)
at System.Messaging.MessageQueue.ReceiveCurrent(System.TimeSpan, Int32, System.Messaging.Interop.CursorHandle, System.Messaging.MessagePropertyFilter, System.Messaging.MessageQueueTransaction, System.Messaging.MessageQueueTransactionType)
at System.Messaging.MessageQueue.Receive()
at Europlanner_.MSMQHandler.ReceiveMessage()
at System.Threading.ThreadHelper.ThreadStart_Context(System.Object)
at System.Threading.ExecutionContext.runTryCode(System.Object)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode, CleanupCode, System.Object)
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
at System.Threading.ThreadHelper.ThreadStart()
如果他们在启动后一分钟左右打开应用程序,则不会出现错误。因此,尽管这确实不是破坏游戏的错误,但我想修复它。
我已经对异常进行了一些搜索,我猜它与权限有关,但奇怪的是它只在启动后不久发生。
出于测试目的,我尝试设置队列的权限,以便所有人和匿名登录具有完全控制权。但这似乎没有帮助。
这些机器都在同一个域中,并且队列在域中我们的一台服务器上。
发生异常的代码如下:
Private Sub ReceiveMessage()
While KeepReading
Dim MSG As Message = ClientQue.Receive()
If Not DateDiff(DateInterval.Minute, MSG.SentTime, Now) >= 1 Then
HandleMessage(MSG)
Else : DebugHandler.WriteLine(DebugTypes.Network, "Removed MSMQ message due to age. (Older than 1 minute") : End If
LastServerCommunication = 0
End While
End Sub
我自己的机器比用户的机器更老更慢,我个人似乎无法在我自己的机器上重现这个错误。我可以使用用户机器进行测试的时间范围是有限的。
有没有人碰巧知道是什么导致了这个异常?
如果我需要发布任何其他信息,请询问。
感谢您的关注。
编辑以回答 Kjell-Åke 的问题:
我使用这个小功能来检查服务是否启动:
Private Function QueueServiceStarted() As Boolean
Dim Services As List(Of ServiceController) = ServiceController.GetServices().ToList
Dim MSMQueue As ServiceController = Services.Find(Function(o) o.ServiceName = "MSMQ")
If Not MSMQueue Is Nothing Then If MSMQueue.Status = ServiceControllerStatus.Running Then Return True
Return False
End Function
编辑以添加异常消息:
"Unable to establish connection with Active Directory Domain Services. Verify that there are sufficient permissions to perform this operation."
编辑:添加更多信息
该应用程序似乎在 Windows 日志中的以下事件之后工作。
"The Message Queuing service is online with Active Directory and fully operational."
所以基本上我猜问题会变成:为什么在我们更快的 PC 上发生这种情况需要这么长时间。