I will try to be brief. For a school project I need a UI with a command prompt (textbox) and a log window (richtextbox).
When we type a command,System::Void MyForm::cmd_textBox_KeyDown(System::Object^ sender, KeyEventArgs^ e)
called another function (in another .cpp) to process it and the function is displayed in my richtextbox.
Some functions send usb frames and receive responses via the interrupt function :
System::Void MyForm::serialPort1_DataReceived(System::Object^ sender, System::IO::Ports::SerialDataReceivedEventArgs^ e)
My concern is the following:
- should my command be launched in another thread than the one managed by the UI?
- when we receive a USB frame and I want to do an AppendText in my richtextbox, the Appentext is sometimes done with a lot of delays (sometimes after other commands).
Currently I update my log via this function, but it still has a delay. If I replace BeginInvoke with Invoke the UI freezes.
void MyForm::Update_log_TextBox(String^ text, Color text_color)
{
Update_log_TextBox_Delegate^ action = gcnew Update_log_TextBox_Delegate(this, &MyForm::Worker);
this->BeginInvoke(action, text, text_color);
}
void MyForm::Worker(String^ text, Color text_color)
{
MyForm::log_TextBox->SelectionColor = text_color;
MyForm::log_TextBox->AppendText(text);
}
Do you have any solutions for me please?
Sorry for my broken English it is not my native language