An unhandled exception of type 'System.Reflection.TargetParameterCountException'
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!
ControlBoxDelegateMethod
takes two parameters (a Label^
and an int
), but you're only passing one (an int
named which
). You're missing the first parameter.
So, it should probably go like this:
local_long_textBox->BeginInvoke(gcnew ControlBoxDelegate(this,&Form1::ControlBoxDelegateMethod), your_label, which);
精彩评论