LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

setting up a .net event hanler for msgqueue

I wish to set up an event handler for a msgqueue like in the following c# code: any ideas?

private const string PROVIDERQUEUE= @"Archimedes\SMTLabelQueue";
///
/// The main entry point for the application.
///

[STAThread]
static void Main(string[] args)
{

// Create an instance of MessageQueue. Set its formatter.
MessageQueue myQueue = null;
try
{
myQueue = new MessageQueue(PROVIDERQUEUE);
}
catch(Exception)
{

}

myQueue.Formatter = new XmlMessageFormatter();

// Add an event handler for the ReceiveCompleted event.
myQueue.ReceiveCompleted +=
new ReceiveCompletedEventHandler(youhavemail);

// Begin the asynch
ronous receive operation.
myQueue.BeginReceive();

while(Console.Read() != 'q');
}

static void youhavemail(Object source,
ReceiveCompletedEventArgs asyncResult)
{
MessageQueue mq = null;
try
{
// Connect to the queue.
mq = (MessageQueue)source;
mq.Formatter = new XmlMessageFormatter(new Type[] {typeof(string)});

// End the asynchronous receive operation.
Message m = mq.EndReceive(asyncResult.AsyncResult);


Console.WriteLine( m.Body.ToString() );
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
// We want to continue reading messages even if we couldn't update the state.
finally
{
// Continue reading messages
mq.BeginReceive();
}
}
}
}
0 Kudos
Message 1 of 2
(2,669 Views)
Hi,

Unfortunatelly LabVIEW does not support .NET events, if you must catch .NET messages you can probably create a dll that catshes those events for you and transfers them to LabVIEW somehow.

You may want to look at ActiveX to send data to LabVIEW, there is a quite complete interface that allows for events and data transfers.

Just my 2 Cents.

Regards,
Juan Carlos
0 Kudos
Message 2 of 2
(2,669 Views)