Form hanging.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aannn
    New Member
    • Sep 2014
    • 4

    Form hanging.

    Hi..
    I have 2 forms. Form1&form2
    code in form1
    Code:
         BackgroundWorker Bw = new BackgroundWorker();
        private void Form1_Load(object sender, EventArgs e)
            {
                 serialPort1.Open();
                            
            }
          private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
            {
                int bytes = serialPort1.BytesToRead;
    
                serialPort1.Read(byte_buffer, 0, bytes);
    
                if (byte_buffer[0] == startup)
                {
                  
                                    
                Bw.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork);
                  Bw.RunWorkerAsync();
                }
            }
    
            private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
            {
                Form2 f2=new Form2();
               f1.Close();
               f2.Show();
            }
    This is my code.mY problem is that form1 is not closing and form2 displays but it hangs 2 or three minutes.And form2 doesnot showing any of controls like textboxes,butto ns etc.I tried so many times..But I didn't get any solution.Please help me.:
    Last edited by Rabbit; Sep 15 '14, 04:01 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Well it looks like you are reading data from a serial port and while you are reading you are creating a new Form2 object...

    Have you considered reading all of the data into memory and then passing the information to a Form2 instance (or multiple Form2 instances if necessary)?

    I have a feeling that you are running into problems opening multiple Form2 instances as you are reading information in your main Form1 instance and this is causing your problems.

    -Frinny

    Comment

    Working...