Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 启动后短时间内MSMQ MessageQueueException出现异常_.net_Vb.net_Msmq - Fatal编程技术网

.net 启动后短时间内MSMQ MessageQueueException出现异常

.net 启动后短时间内MSMQ MessageQueueException出现异常,.net,vb.net,msmq,.net,Vb.net,Msmq,我有一个多用户规划应用程序,其中客户端将包含其更改的msmq消息发送到服务器应用程序,服务器应用程序处理这些消息,计算库存/时间短缺,然后向所有连接的客户端发送消息,更新其数据以显示更改 这是工作得很好,除了一个例外,一直困扰着我 这基本上只发生在启动后的少数速度更快的PC(带SSD、I7等)上 ExceptionInformation: System.Messaging.MessageQueueException Stack: at System.Messaging.MessageQue

我有一个多用户规划应用程序,其中客户端将包含其更改的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上实现这一点。

我遇到了这个问题,最后我使用了一个事件日志触发器,等待MSMQ与ad服务器握手

我只是不喜欢尝试/捕捉/睡眠循环直到它出现。 修复它可能有点太复杂了,但我觉得值得

通过这种方式,您可以构造代码,区分客户端计算机上的启动错误和MSMQ正在等待AD服务器


在异常中您会得到什么错误代码?是否MSMQ服务尚未启动?@Kjell-Åke Gafvelin服务已启动。我有一个小函数,在应用程序启动后立即运行检查。我已经在上面的帖子中添加了代码。你必须回答Kjell,如果你不发布异常消息和MessageQueueErrorCode@HansPassant对不起,我迟了答复。周五我们的网络中断了。昨天我没能做任何测试。异常的消息似乎是(从荷兰语翻译过来)“无法与Active Directory建立连接。请验证是否有足够的权限执行此操作。”。如前所述,大约一两分钟后,应用程序就可以正常运行了。就在启动之后,这个错误似乎突然出现了。在我们速度较慢的pc上似乎也不会出现这种情况。因此,可能Active Directory确实需要一段特定的时间来准备,而SSD pc完成整个启动任务的速度太快了。如果这些是新机器,并且没有更新到其他机器的状态,那么可能会有windows更新。作为解决方法,您可以添加一个检查连接是否准备好,并可能将所有方法封装在try..catch块中,以确保错误不会停止整个程序。对不起,我有一段时间没有检查。这确实也是我们找到的解决办法。似乎是解决这个问题最干净、最可靠的方法。