.NET C++ writing UI from other thread
In .Net C++, I want to write the serial input to a textB开发者_开发百科ox on the UI. But of course the serial input is on another thread. I am guessing that I need to pass in a delegate to the serial thread when I create it to run the function below called updateTextBoxes. I tried making a delegate as below but I am stuck at what I need to put in the argument list when the delegate is created. This is all in my Form1 class.
public delegate void MyDel();
void updateTextBoxes()
{
this->local_long_textBox->Text = "Test!!!!!!!"
}
private: void startUp()
{
MyDel^ DelInst;
DelInst = gcnew MyDel( ??? what goes in here?
you would pass the arguments that are required for the constructor
Call Invoke
or BeginInvoke
on the text box passing a delegate that sets the Text property.
Invoke
will execute the delegate on the thread associated with the text box. BeginInvoke
does the same but asynchronously.
精彩评论