本文整理匯總了VB.NET中System.Messaging.MessageQueue.EndReceive方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET MessageQueue.EndReceive方法的具體用法?VB.NET MessageQueue.EndReceive怎麽用?VB.NET MessageQueue.EndReceive使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Messaging.MessageQueue
的用法示例。
在下文中一共展示了MessageQueue.EndReceive方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: MyNewQueue
' 導入命名空間
Imports System.Messaging
Imports System.Threading
' Provides a container class for the example.
Public Class MyNewQueue
' Define static class members.
Private Shared signal As New ManualResetEvent(False)
Private Shared count As Integer = 0
' Provides an entry point into the application.
'
' This example performs asynchronous receive
' operation processing.
Public Shared Sub Main()
' Create an instance of MessageQueue. Set its formatter.
Dim myQueue As New MessageQueue(".\myQueue")
myQueue.Formatter = New XmlMessageFormatter(New Type() _
{GetType([String])})
' Add an event handler for the ReceiveCompleted event.
AddHandler myQueue.ReceiveCompleted, AddressOf _
MyReceiveCompleted
' Begin the asynchronous receive operation.
myQueue.BeginReceive()
signal.WaitOne()
' Do other work on the current thread.
Return
End Sub
' Provides an event handler for the ReceiveCompleted
' event.
Private Shared Sub MyReceiveCompleted(ByVal [source] As _
[Object], ByVal asyncResult As ReceiveCompletedEventArgs)
Try
' Connect to the queue.
Dim mq As MessageQueue = CType([source], MessageQueue)
' End the asynchronous receive operation.
Dim m As Message = _
mq.EndReceive(asyncResult.AsyncResult)
count += 1
If count = 10 Then
signal.Set()
End If
' Restart the asynchronous receive operation.
mq.BeginReceive()
Catch
' Handle sources of MessageQueueException.
' Handle other exceptions.
End Try
Return
End Sub
End Class