I created an UI in Visual Studio 2015. From the header file created from the UI, I create several threads. In this threads I call an external method within a class. Then, from this method I would like to print results adding them to a listbox that is in the UI.
However, it is not working. I tried with Delegate
, but it did not work either.
Creation of threads in gui.h:
FaceCheck^ f1 = gcnew FaceCheck("hello");
System::Threading::Thread^ t1 = gcnew System::Threading::Thread(gcnew System::Threading::ThreadStart(f1, &FaceCheck::WriteText));
t1->Start();
FaceCheck^ f2 = gcnew FaceCheck("goodnight");
System::Threading::Thread^ t2 = gcnew System::Threading::Thread(gcnew System::Threading::ThreadStart(f2, &FaceCheck::WriteText));
t2->Start();
FaceCheck class (.cpp):
#include "FaceCheck.h"
#include "gui.h"
FaceCheck::FaceCheck(System::String^ text_out)
{
text = text_out;
}
void FaceCheck::WriteText()
{
FACE::gui::textLog->Items->Add(text);
}
And then, I changed FACE::gui::textLog
in gui.h
to public: static
I also read about checking if textLog->InvokeRequired
, but I did not get to use Delegate
.