I am trying to update a Winform picturebox from another class running on another thread. I followed the answer at Update WinForm Controls from another thread _and_ class which appears to have all the information except how, exactly, to pass the reference to the Winform/Winform member function to the thread in the constructor/how to call the Winform member function from the thread.
My code is as follows:
//Camera.h
public class CameraThread
{
public:
CameraThread(????)
{
// constructor
}
void DoSomething
{
// call UpdateBox on Form1
????
}
};
//Form1.h
namespace SV7 {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
public ref class Form1 : public System::Windows::Forms::Form
{
private: CameraThread* CT;
private: boost::thread* ImageACQ;
public: delegate void UpdateDelegate(void);
public:
Form1(void)
{
CT = new CameraThread(????);
boost::thread* ImageACQ = new boost::thread(&CameraThread::ImageAcquisition,CT);
InitializeComponent();
InitializeCanny();
}
void UpdateBox(void)
{
if (this->RawImageBox->InvokeRequired)
{
UpdateDelegate^ d = gcnew UpdateDelegate(this,&Form1::UpdateBox);
this->RawImageBox->BeginInvoke(d);
}
else
{
}
}
};
}
Where I have put the ????, I do not know what syntax to use to pass/call the member function. I assume that a forward declaration of Form1 is needed in my Camera.h but was having trouble referencing the actual form class in Form.h. However, if a straight function pointer was used, then I do not think that would be the way to go.
By way of background, I am using VS2010 SE C++. I am trying to have an separate thread that grabs images from a webcam, processed them using OpenCV, and then displays the results in a picturebox on the GUI thread.
I am just ignorant of how to do this and would appreciate any guidance. Thanks in advance/