나는 내가 메인 창 (MainForm)에서하여 RichTextBox (TXT) 내가 SerialTranseiver (MainForm 백만)라는 다른 양식 통과 한다른 폼의 스레드에서 폼의 RichTextBox에 텍스트를 붙여 넣는 방법?
public void postTxt(String txt)
{
//do some database update
this.Txt.AppendText(txt);
}
공개 방법을 C# 어디에요에서 윈도우 폼 응용 프로그램이 MainForm을 생성자의 매개 변수로 사용합니다.
SerialTranseiver(MainForm mn)
{
//-----other codes
this.tmpMain=mn;
}
이 두 번째 클래스는하여 SerialPort (스포츠)와 데이터를 대기하고있다 자사의 SerialDataReceivedEventHandler에있는 데이터는 mn.postTxt (Sport.ReadLine(). toString())
void Sport_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
mn.postTxt(Sport.ReadLine().toString());
//---database updating codes and other stuff
}
를 호출 할 때마다 이로 인해
Cross-thread operation not valid: Control 'Txt' accessed from a thread other than the thread it was created on
예외가 발생합니다.이 문제를 어떻게 해결할 수 있습니까?