问题描述
我有一个单线程应用程序。它应该连接到本地 MSMQ 队列,一旦收到消息,它应该在继续侦听其他消息之前对其进行处理。消息包含应该插入到数据库表中的数据。但是在插入数据之前,它会进行查询以查看该项目是否已经存在。但是,我认为通过为 ReceiveCompleted 创建一个处理程序,如果队列中有多条消息,那么就会产生多个线程。那会发生吗?如果有可能在两条消息中都存在重复数据,并且我的 sql 查询可能看不到任何重复,因为第二个线程仍在工作并且尚未将其数据插入到数据库表中。
Dim objQueue As New MessageQueue(ConfigurationManager.AppSettings("myQueuePath"))
AddHandler objQueue.ReceiveCompleted,AddressOf QueueReceived
objQueue.BeginReceive()
Private Sub QueueReceived(source As Object,asyncResult As ReceiveCompletedEventArgs)
Dim mq = DirectCast(source,MessageQueue)
Dim objMessage As Message = nothing
Try
mq.Formatter = New Xmlmessageformatter(New [String]() {"System.String,mscorlib"})
objMessage = mq.EndReceive(asyncResult.AsyncResult)
Dim strMessage As String = objMessage.Body.ToString()
'Call routine to read data,check for suplicates and then insert into database
ProcessBXRS(objMessage)
Catch ex As Exception
'Do some exception handling
End Try
'Listen for next message
mq.BeginReceive()
End Sub
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)