Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Messaging
- Imports System.IO
- Imports System.Diagnostics
- Imports System.ComponentModel
- Public Class MainForm
- Private m_Path As String = ".\private$\orders"
- Private b_Path As String = ".\private$\begin"
- Public recmes As InfoMessage
- Public DrinkCount As Integer = 0
- Public GenCount As Integer = 0
- Public listenerID As String
- Public currentProcess As Process
- Public WhatKindOfMessageID As String
- ' Starts reading messages from the queue.
- Private Sub HookQueue()
- Try
- If qOrders Is Nothing Then
- qOrders = New System.Messaging.MessageQueue(m_Path)
- End If
- ' Start waiting for messages to arrive.
- qOrders.BeginReceive()
- Catch exp As MessageQueueException
- My.Application.Log.WriteEntry(exp.Message)
- Catch exp As Exception
- My.Application.Log.WriteEntry(exp.Message)
- End Try
- End Sub
- ' Stops reading messages from the queue.
- Private Sub UnhookQueue()
- Try
- qOrders.Close()
- Catch exp As Exception
- My.Application.Log.WriteEntry(exp.Message)
- End Try
- End Sub
- ' Event Handler for message recieved event.
- Private Sub qOrders_ReceiveCompleted(ByVal sender As Object, ByVal e As System.Messaging.ReceiveCompletedEventArgs) Handles qOrders.ReceiveCompleted
- Try
- ' Set the formatter to indicate body contains an Order.
- qOrders.Formatter = New XmlMessageFormatter(New Type() {GetType(InfoMessage)})
- ' Get the message.
- Dim m As Message
- m = qOrders.EndReceive(e.AsyncResult)
- recmes = CType(m.Body, InfoMessage)
- OrderListbox.Items.Add(m.Label)
- OrderListbox.Items.Add(recmes.Fuser)
- OrderListbox.Items.Add(recmes.Fpass)
- OrderListbox.Items.Add(recmes.Flink)
- ' Add the message to the Listbox.
- 'OrderListbox.Items.Add(m.Label)
- ReplyBox.Text = m.Label
- ' Now continue listening for messages.
- qOrders.BeginReceive()
- Catch exp As MessageQueueException
- My.Application.Log.WriteEntry(exp.Message)
- Catch exp As Exception
- My.Application.Log.WriteEntry(exp.Message)
- End Try
- End Sub
- ' Clears the Listbox.
- Private Sub ClearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearButton.Click
- OrderListbox.Items.Clear()
- End Sub
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- ' Create the private queue if it does not exist.
- Try
- If Not MessageQueue.Exists(".\private$\orders") Then
- MessageQueue.Create(".\private$\orders")
- End If
- Catch ex As Exception
- End Try
- ' Creates the START queue if it does not exist.
- Try
- If Not MessageQueue.Exists(".\private$\begin") Then
- MessageQueue.Create(".\private$\begin")
- End If
- Catch ex As Exception
- End Try
- ' Create the RETURN queue if it does not exist.
- Try
- If Not MessageQueue.Exists(".\private$\return") Then
- MessageQueue.Create(".\private$\return")
- End If
- Catch ex As Exception
- End Try
- BeginHookQueue()
- currentProcess = Process.GetCurrentProcess()
- ReturnQueue.Send("", currentProcess.Id.ToString)
- End Sub
- ' Toggles listening for messages.
- Private Sub Listen_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Listen.CheckedChanged
- If Listen.Checked Then
- Try
- HookQueue()
- Catch exp As MessageQueueException
- My.Application.Log.WriteEntry(exp.Message)
- Catch exp As Exception
- My.Application.Log.WriteEntry(exp.Message)
- End Try
- Else
- UnhookQueue()
- End If
- End Sub
- Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
- BeginUnhookQueue()
- End
- End Sub
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- Try
- ' when we are stopped.
- If qOrders Is Nothing Then
- qOrders = New System.Messaging.MessageQueue(m_Path)
- End If
- Dim m As Message
- ' Set the formatter to indicate body contains an Order.
- qOrders.Formatter = New XmlMessageFormatter(New Type() {GetType(InfoMessage)})
- Dim TestEnum As System.Messaging.MessageEnumerator
- TestEnum = qOrders.GetMessageEnumerator2
- Dim CurMsgID As String
- While (TestEnum.MoveNext())
- m = TestEnum.Current
- If (m.Label = WhatKindOfMessageID) Then
- CurMsgID = TestEnum.Current.Id
- m = qOrders.ReceiveById(CurMsgID)
- recmes = CType(m.Body, InfoMessage)
- OrderListbox.Items.Add(m.Label)
- OrderListbox.Items.Add(recmes.Fuser)
- OrderListbox.Items.Add(recmes.Fpass)
- OrderListbox.Items.Add(recmes.Flink)
- End If
- End While
- Catch exp As MessageQueueException
- My.Application.Log.WriteEntry(exp.Message)
- Catch exp As Exception
- My.Application.Log.WriteEntry(exp.Message)
- End Try
- End Sub
- ' Starts reading messages from the begin queue.
- Private Sub BeginHookQueue()
- Try
- ' when we are stopped.
- If StartQueue Is Nothing Then
- StartQueue = New System.Messaging.MessageQueue(b_Path)
- End If
- ' Start waiting for messages to arrive.
- StartQueue.BeginReceive()
- Catch exp As MessageQueueException
- My.Application.Log.WriteEntry(exp.Message)
- Catch exp As Exception
- My.Application.Log.WriteEntry(exp.Message)
- End Try
- End Sub
- ' Stops reading messages from the queue.
- Private Sub BeginUnhookQueue()
- Try
- StartQueue.Close()
- Catch exp As Exception
- My.Application.Log.WriteEntry(exp.Message)
- End Try
- End Sub
- ' Event Handler for message recieved event.
- Private Sub StartQueue_ReceiveCompleted(ByVal sender As Object, ByVal e As System.Messaging.ReceiveCompletedEventArgs) Handles StartQueue.ReceiveCompleted
- Try
- ' Get the message.
- Dim m As Message
- m = StartQueue.EndReceive(e.AsyncResult)
- WhatKindOfMessageID = m.Label
- MsgBox(currentProcess.Id.ToString, , "StartQ Message")
- ' Now continue listening for messages.
- ' StartQueue.BeginReceive()
- Catch exp As MessageQueueException
- My.Application.Log.WriteEntry(exp.Message)
- Catch exp As Exception
- My.Application.Log.WriteEntry(exp.Message)
- End Try
- End Sub
- End Class
- Public Class InfoMessage
- Public Fuser As String
- Public Fpass As String
- Public Flink As String
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement