Event handler in methods of the same class
<p>I'm working on my project using C#, .Net 2.0 and VS2008.
Briefly, my application communicates with the device via USB. And I have a problem with the processing of incoming messages from the device.</p>

<p>This is handler for event "we got something from device":</p>

<pre><code>private void usb_OnDataRecieved(object sender, DataRecievedEventArgs args)
</code></pre>

<p>It never called in methods of the same class (I use partial class):</p>

<pre><code>private void btn_indication_start_Click(object sender, EventArgs e)
{
            currentTest = "indication";
            this.ControlBox = false;

            bool isTestPassed = false;

            int timeout = 1000;

            sendMessageToDevice("A9 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"); //device should respond to this message

            System.Diagnostics.Stopwatch stopwatch = System.Diagnostics.Stopwatch.StartNew();
            while (true)
            {
                if (stopwatch.ElapsedMilliseconds &gt;= timeout)
                    break;
                Thread.Sleep(1);
            }

            if (!newMessageArrived)  //this bool variable always false :(
            {
                MessageBox.Show("Timeout!"); //usb_OnDataRecieved called only in this block! And newMessageArrived become true
                                             //and when we remove MessageBox, it don't called ever!
                this.ControlBox = true;
                currentTest = "";
                return;
            }

            //do something else with device...

            this.ControlBox = true;
            currentTest = "";
        }
</code></pre>

<p>How to fix this problem with event handler?</p>

<p>P.S. It works fine when I send/receive messages via form's buttons and textboxes:</p>

<pre><code>private void btn_send_Click(object sender, EventArgs e)
        {
            try
            {
                string text = this.tb_send.Text + " ";
                text.Trim();
                string[] arrText = text.Split(' ');
                byte[] data = new byte[arrText.Length];

                for (int i = 0; i &lt; arrText.Length; i++)
                {
                    if (arrText[i] != "")
                    {
                        int value = Int32.Parse(arrText[i], System.Globalization.NumberStyles.HexNumber);
                        data[i] = (byte)Convert.ToByte(value);
                    }
                }

                if (this.usb.SpecifiedDevice != null)
                {
                    this.usb.SpecifiedDevice.SendData(data);
                }
                else
                {
                    MessageBox.Show("Device not found, plug it");
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

private void usb_OnDataRecieved(object sender, DataRecievedEventArgs args)
        {
            if (InvokeRequired)
            {
                try
                {
                    Invoke(new DataRecievedEventHandler(usb_OnDataRecieved), new object[] { sender, args });
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }
            else
            {

                string rec_data = "Data: ";
                foreach (byte myData in args.data)
                {
                    if (myData.ToString("X").Length == 1)
                    {
                        rec_data += "0";
                    }

                    rec_data += myData.ToString("X") + " ";
                }

                this.lb_read.Items.Insert(0, rec_data);
                lastMessageFromUsb = rec_data;
                newMessageArrived = true;
            }
        }
</code></pre>
