本文整理汇总了VB.NET中System.Messaging.MessageQueue.Send方法的典型用法代码示例。如果您正苦于以下问题:VB.NET MessageQueue.Send方法的具体用法?VB.NET MessageQueue.Send怎么用?VB.NET MessageQueue.Send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Messaging.MessageQueue
的用法示例。
在下文中一共展示了MessageQueue.Send方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: MyNewQueue
' 导入命名空间
Imports System.Messaging
Public Class MyNewQueue
'
' Provides an entry point into the application.
'
' This example sends a message to a queue.
'
Public Shared Sub Main()
' Create a new instance of the class.
Dim myNewQueue As New MyNewQueue
' Send a message to a queue.
myNewQueue.SendMessage()
Return
End Sub
'
' Sends a message to a queue.
'
Public Sub SendMessage()
' Connect to a queue on the local computer.
Dim myQueue As New MessageQueue(".\myQueue")
' Send a message to the queue.
If myQueue.Transactional = True Then
' Create a transaction.
Dim myTransaction As New MessageQueueTransaction
' Begin the transaction.
myTransaction.Begin()
' Send the message.
myQueue.Send("My Message Data.", myTransaction)
' Commit the transaction.
myTransaction.Commit()
Else
myQueue.Send("My Message Data.")
End If
Return
End Sub
End Class
示例2: MyNewQueue
' 导入命名空间
Imports System.Messaging
Public Class MyNewQueue
'
' Provides an entry point into the application.
'
' This example sends and receives a message from
' a transactional queue.
'
Public Shared Sub Main()
' Create a new instance of the class.
Dim myNewQueue As New MyNewQueue
' Send a message to a queue.
myNewQueue.SendMessageTransactional()
' Receive a message from a queue.
myNewQueue.ReceiveMessageTransactional()
Return
End Sub
'
' Sends a message to a queue.
'
Public Sub SendMessageTransactional()
' Connect to a queue on the local computer.
Dim myQueue As New MessageQueue(".\myTransactionalQueue")
' Send a message to the queue.
If myQueue.Transactional = True Then
' Create a transaction.
Dim myTransaction As New MessageQueueTransaction
' Begin the transaction.
myTransaction.Begin()
' Send the message.
myQueue.Send("My Message Data.", myTransaction)
' Commit the transaction.
myTransaction.Commit()
End If
Return
End Sub
'
' Receives a message containing an Order.
'
Public Sub ReceiveMessageTransactional()
' Connect to a transactional queue on the local computer.
Dim myQueue As New MessageQueue(".\myTransactionalQueue")
' Set the formatter.
myQueue.Formatter = New XmlMessageFormatter(New Type() _
{GetType([String])})
' Create a transaction.
Dim myTransaction As New MessageQueueTransaction
Try
' Begin the transaction.
myTransaction.Begin()
' Receive the message.
Dim myMessage As Message = _
myQueue.Receive(myTransaction)
Dim myOrder As [String] = CType(myMessage.Body, _
[String])
' Display message information.
Console.WriteLine(myOrder)
' Commit the transaction.
myTransaction.Commit()
Catch e As MessageQueueException
' Handle nontransactional queues.
If e.MessageQueueErrorCode = _
MessageQueueErrorCode.TransactionUsage Then
Console.WriteLine("Queue is not transactional.")
End If
' Else catch other sources of a MessageQueueException.
' Roll back the transaction.
myTransaction.Abort()
' Catch other exceptions as necessary, such as
' InvalidOperationException, thrown when the formatter
' cannot deserialize the message.
End Try
Return
End Sub
End Class
示例3: MainClass
' 导入命名空间
Imports System
Imports System.Messaging
Public Class MainClass
Shared Sub Main()
Dim Greeting As String = "Hello World!"
Dim mQ As MessageQueue
If MessageQueue.Exists(".\Private$\HelloWorld") Then
mQ = New MessageQueue(".\Private$\HelloWorld")
Else
mQ = MessageQueue.Create(".\Private$\HelloWorld")
End If
mQ.Send(Greeting, "HelloWorld")
Console.WriteLine("Greeting Message Sent to Private Queue.")
End Sub
End Class