Hi to all,
I am using c# since last week so I'am not so expert.
I have this problem: I have created a delegate function to handle the result of the data received and managed it with the method .InvokeRequire and .Invoke().
I show the code
Everything works very well till I close the form exactly while receiving datas.
The program blocks at line
and wait for I don't know what.
I try to add this code on the Closing event of the form
but it is not helpfull.
Any ideas?
Thank's for all.
I am using c# since last week so I'am not so expert.
I have this problem: I have created a delegate function to handle the result of the data received and managed it with the method .InvokeRequire and .Invoke().
I show the code
Code:
delegate void SetCallBackRxMsg();
private void ReceivedSerialData(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
if (btnReception.Text == "Stop Reception")
{
try
{
iRxIndex += controlSerialPort.Read(byRxMessage, iRxIndex, controlSerialPort.BytesToRead);
}
catch
{
}
finally
{
if (iRxIndex > 1 && iRxIndex >= iLenMsg)
{
this.RxMessage();
}
}
}
private void RxMessage()
if (this.InvokeRequired)
{
this.Invoke(new SetCallBackRxMsg(RxMessage), new object[] { });
}
else
{
// message received
// ...
}
Everything works very well till I close the form exactly while receiving datas.
The program blocks at line
Code:
this.Invoke(new SetCallBackRxMsg(RxMessage), new object[] { });
I try to add this code on the Closing event of the form
Code:
private void myForm_FormClosing(object sender, FormClosingEventArgs e)
{
if (controlSerialPort.IsOpen)
{
controlSerialPort.DiscardInBuffer();
controlSerialPort.Close();
}
}
Any ideas?
Thank's for all.