Click here to Skip to main content
15,902,938 members

Comments by Amit kumar pathak (Top 4 by date)

Amit kumar pathak 14-Apr-11 5:27am View    
Thanks to your solution your solution is correct in normal case actually in my program problem was inPtr and Marshal.Copy(buffer, 0, HeaderPtr, buffer.Length);. here it was taking so much of time, now i have use inPtr with GCHandle and its working very smooth.
Amit kumar pathak 15-Mar-11 1:49am View    
Yes you are correct i also found that problem while converting from binary to structure...
Amit kumar pathak 14-Mar-11 3:12am View    
i run your code using source provided by you(http://www.codeproject.com/KB/cs/Harlinn_Messaging.aspx) worked well, but when i implement it in my program then it gets hanged within a minute and stopped working.... Kindly help me out your help to make running program will be so helpfull...if you provide your email then i'll send fulll code ...

namespace udpConsume
{

public partial class FormReceive : Form
{
private MessageQueue messageQueue;
private bool isRunning;

public FormReceive()
{
InitializeComponent();
InitializeQueue();
}

private void InitializeQueue()
{
receivedCounter = 0;
string queuePath = @".\private$\myquelocal";
if (!MessageQueue.Exists(queuePath))
{
messageQueue = MessageQueue.Create(queuePath);
}
else
{
messageQueue = new MessageQueue(queuePath);
}
isRunning = true;
messageQueue.Formatter = new BinaryMessageFormatter();
messageQueue.ReceiveCompleted += OnReceiveCompleted;
messageQueue.BeginReceive();
}

private delegate void LogMessageDelegate(string text);
private void LogMessage(string text)
{
if (InvokeRequired)
{
Invoke(new LogMessageDelegate(LogMessage), text);
}
else
{
messageTextBox.AppendText(text + Environment.NewLine);
}
}

private int receivedCounter;
private void OnReceiveCompleted(Object source, ReceiveCompletedEventArgs asyncResult)
{
try
{
MessageQueue mq = (MessageQueue)source;

if (mq != null)
{
try
{
System.Messaging.Message message = null;
try
{
message = mq.EndReceive(asyncResult.AsyncResult);
}
catch (Exception ex)
{
LogMessage(ex.Message);
}
if (message != null)
{
byte[] buffer = (byte[])message.Body;
if (buffer.Length > 0)
{
receivedCounter++;
if ((receivedCounter % 10) == 0)
{
TBCastMessageHeader bcastHeader = new TBCastMessageHeader();
IntPtr bcastHeaderPtr;
bcastHeaderPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(TBCastMessageHeader)));
Marshal.Copy(buffer, 0, bcastHeaderPtr, buffer.Length);
bcastHeader = (TBCastMessageHeader)(Marshal.PtrToStructure(bcastHeaderPtr, typeof(TBCastMessageHeader)));


//MessageBox.Show(bcastHeader.MessageCode.ToString());
try
{
LogMessage(bcastHeader.MessageCode.ToString());
string ChngSign = "";

switch (bcastHeader.MessageCode)
{

case 1001: //usp_Insert1001data

TMarketUpdateMsg marketupdMsg;
IntPtr marketPtr;
marketPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(TMarketUpdateMsg)));
Marshal.C
Amit kumar pathak 12-Mar-11 8:22am View    
when i tried with this cpu goes to 40% and suddenly stooped exe.. kindly help me out..