Welcome to the new platform of Programmers Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use it's exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.
Initialising global variables for event handlers??
I wrote a little program in C# but it stops responding whenever I call the function test(see code below). I have a serialport event handle and it increments a variable. Then there is a function that waits for that variable to reach 10 before it continues but the program does not like that.
The program in a nutshell is like this:
//The variable is initialised as global
int packet_size_rx = 0;
//Then there is a serial port handle that increments the variable
void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
//the number of bytes available from serial port
int bytes_rx = serialPort1.BytesToRead;
//The global variable is being updated
//Then there is a function that waits for the variable to reach 10
//wait for the variable to reach 10
while (packet_size_rx < 10 );
The program stops responding when it gets to the while loop above. Is it because I initialised the variable wrong or did I use it wrong?