Answer the question
In order to leave comments, you need to log in
How to call a form from a thread?
Hello. I'm making a web face for an application. For this I use the mongoose web server. The application is written in c++ .Net.
The main application and the server are in different threads. For interaction between them, an intermediary class is implemented, implemented as a singleton.
The task is reduced to that by means of the intermediary from the server to call functions of the form.
Form Code
public ref class MainForm : public System::Windows::Forms::Form{
...
public:MainForm(void){
doWithEffect^ up;
up = gcnew doWithEffect(this,&hitekfloor::MainForm::moveEffectUp);
doWithEffect^ down;
down = gcnew doWithEffect(this,&hitekfloor::MainForm::moveEffectDown);
MediatorBetweenProgrammAndWebServer::getInstance()->setFucntionForEffects(up,down);
}
public: bool moveEffectUp(int num){/*Эта функция должна вызываться из MediatorBetweenProgrammAndWebServer */
if (this->InvokeRequired){
doWithEffect^ d = gcnew doWithEffect(this, &moveEffectUp);
this->Invoke(d, gcnew array<Object^> {num});
}else
SchedulerModel->MoveItemUp(num);
return true;
}
};
public delegate bool doWithEffect(int num);
ref class MediatorBetweenProgrammAndWebServer : System::Object{
public:
static MediatorBetweenProgrammAndWebServer^ getInstance();
void resetInstance();
void setFucntionForEffects(doWithEffect^ up, doWithEffect^ down);
void MoveEffectUp(unsigned int itemIndex);
void MoveEffectDown(unsigned int itemIndex);
protected:
MediatorBetweenProgrammAndWebServer();
~MediatorBetweenProgrammAndWebServer();
private:
static MediatorBetweenProgrammAndWebServer^ m_mediator;
doWithEffect^ upEffect;
doWithEffect^ downEffect;
};
mediator.cpp
...
void MediatorBetweenProgrammAndWebServer::setFucntionForEffects(doWithEffect^ up, doWithEffect^ down){
upEffect = up;
downEffect = down;
return;
}
...
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question