Skip to content

Instantly share code, notes, and snippets.

@steefjan
Created August 13, 2010 13:59
Show Gist options
  • Save steefjan/522932 to your computer and use it in GitHub Desktop.
Save steefjan/522932 to your computer and use it in GitHub Desktop.
/// <summary>
/// Event Handler for Read button click
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnRead_Click(object sender, EventArgs e)
{
//create an instance MessageQueue, which points to the already existing Private Queue
MessageQueue mq = new MessageQueue(@".\PRIVATE$\SALESFORCECONTACT");
//New instance of Message
System.Messaging.Message mes = new System.Messaging.Message();
try
{
//Receive message
mes = mq.Receive(new TimeSpan(0, 0, 3));
//Instantie Binary Reader
BinaryReader reader = new BinaryReader(mes.BodyStream);
int count = (int)mes.BodyStream.Length;
byte[] bytes = reader.ReadBytes(count);
txtAccountDetails.Text = Encoding.UTF8.GetString(bytes);
}
catch
{
//Case no message is read
txtAccountDetails.Text = "No Message";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment