Click here to Skip to main content
15,920,005 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi..
When I write the following code I got this error.

C#
 byte[] byte_buffer = new byte[20];

 private void serialPort1_DataReceived(objectsender,System.IO.Ports.SerialDataReceivedEventArgs e)
        {
            int bytes = serialPort1.BytesToRead;
           
            serialPort1.Read(byte_buffer, 0, bytes);

            count++;
            if (byte_buffer[0] == startup)
            {
               
                 this. Close();//Error
                Application. Run(new Form4());
               
               
              }
}           



Cross-thread operation not valid: Control 'Form1' accessed from a thread other than the thread it was created on.
How can I rectify this error.? I searched in Google..But am new to this area.so can anyone tell me the answer?
Posted
Comments
[no name] 10-Sep-14 7:29am    
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.invoke(v=vs.110).aspx
DPSSS2 10-Sep-14 7:45am    
how it implement in my program?
DPSSS2 10-Sep-14 23:36pm    
I tried background worker also. But I get the same error message.

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900