private: delegate System::Void delegate_function(void);

if(this->InvokeRequired)
{
AsyncCallback ^ac = gcnew AsyncCallback(&WCS::MainForm::delegate_function_callback);
delegate_function ^df = gcnew delegate_function(this, &WCS::MainForm::function_to_invoke);

System::IAsyncResult ^asyncresult;

//Begin invoke command here.
try
{
	asyncresult = df->BeginInvoke(ac, df);
	//asyncresult = this->statusLight->BeginInvoke(ac, df);
	//this->commsStatusLight->EndInvoke(asyncresult);
	//df->Invoke();
	df->EndInvoke(asyncresult);
	//df->DynamicInvoke(ac, df);
}
catch (...)
{
	std::cerr << "caught";
}
}

public: System::Void function_to_invoke()
{
	this->statusLight->BackColor = DataClass->getlight();
	this->statusLight1->BackColor = DataClass->getight1();
	this->butCheck->Enabled = DataClass->getenable();
	this->status->Text = DataClass->getstatus();                    //this line returns instead of finishing
	this->status1->Text = DataClass->getstatus1();
}

private: static System::Void delegate_function_callback(System::IAsyncResult ^asyncresult)
{
	//delegate_function ^df = gcnew delegate_function(&WCS::MainForm::function_to_invoke);
                //df->EndInvoke(asyncresult);
}

I am at my wits end with this. The invoke works the first time through, but when all this gets called again, it doesnt get past the line marked above in function_to_invoke. It also throws an exception after the first time. First time works perfect, half works any time after. Please help if you know anything, any advice would be appreciated. Thanks.

Recommended Answers

All 3 Replies

You've got a question about that are do you just like posting code? :P

Hit the button too early, I edited it. :)

I'm not into windowsprogramming, but shouldn't you dispose() 'df' somewhere before using it again?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.