VB.Net by API/System.Messaging/MessageQueue — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 12:50, 26 мая 2010
Содержание
MessageQueue.Create
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
MessageQueue.Exists
Imports System
Imports System.IO
Imports System.Messaging
Public Class MainClass
Shared Sub Main()
Dim mQ As MessageQueue
Dim mes As Message
Dim X As String
Dim br As BinaryReader
If MessageQueue.Exists(".\Private$\HelloWorld") Then
mQ = New MessageQueue(".\Private$\HelloWorld")
Else
Console.WriteLine("Queue doesn"t exist.")
Return
End If
Try
mes = mQ.Receive(New TimeSpan(0, 0, 3))
br = New BinaryReader(mes.BodyStream)
X = New String(br.ReadChars(CType(mes.BodyStream.Length, Integer)))
Console.WriteLine("Received Message: {0}", X)
Catch
Console.WriteLine("No Message to Receive.")
End Try
End Sub
End Class
MessageQueue.Receive
Imports System
Imports System.IO
Imports System.Messaging
Public Class MainClass
Shared Sub Main()
Dim mQ As MessageQueue
Dim mes As Message
Dim X As String
Dim br As BinaryReader
If MessageQueue.Exists(".\Private$\HelloWorld") Then
mQ = New MessageQueue(".\Private$\HelloWorld")
Else
Console.WriteLine("Queue doesn"t exist.")
Return
End If
Try
mes = mQ.Receive(New TimeSpan(0, 0, 3))
br = New BinaryReader(mes.BodyStream)
X = New String(br.ReadChars(CType(mes.BodyStream.Length, Integer)))
Console.WriteLine("Received Message: {0}", X)
Catch
Console.WriteLine("No Message to Receive.")
End Try
End Sub
End Class
MessageQueue.Send
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
New MessageQueue
Imports System
Imports System.IO
Imports System.Messaging
Public Class MainClass
Shared Sub Main()
Dim mQ As MessageQueue
Dim mes As Message
Dim X As String
Dim br As BinaryReader
If MessageQueue.Exists(".\Private$\HelloWorld") Then
mQ = New MessageQueue(".\Private$\HelloWorld")
Else
Console.WriteLine("Queue doesn"t exist.")
Return
End If
Try
mes = mQ.Receive(New TimeSpan(0, 0, 3))
br = New BinaryReader(mes.BodyStream)
X = New String(br.ReadChars(CType(mes.BodyStream.Length, Integer)))
Console.WriteLine("Received Message: {0}", X)
Catch
Console.WriteLine("No Message to Receive.")
End Try
End Sub
End Class