I created a BeginInvoke so I could write to a text box from a non-UI thread. Thread A calls a delegate which runs testFunc in thread A’s context. testFunc then does a BeginInvoke which runs the empty function ControlBoxDelegateMethod. If the BeginInvoke line is removed, the program runs. But if it is left in, I get the following exception:
An unhandled exception of type ‘System.Reflection.TargetParameterCountException’ occurred in mscorlib.dll Additional information: Parameter count mismatch.
private:
//delegate void ControlBoxDelegate(Label^ myControl,int whichControl);
void ControlBoxDelegateMethod(Label^ myControl,int whichControl)
{
// myControl->Text = "Test!!!!!!!";
}
public:
void testFunc()
{
int which = 3;
local_long_textBox->BeginInvoke(gcnew ControlBoxDelegate
(this,&Form1::ControlBoxDelegateMethod),which);
}
Could anyone shed some light on what I am doing wrong here? Thanks!
ControlBoxDelegateMethodtakes two parameters (aLabel^and anint), but you’re only passing one (anintnamedwhich). You’re missing the first parameter.So, it should probably go like this: