N
None
Hello
To get an understanding of UI threads in C++/CLI, I attempted to
duplicate the following C# example:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/html/winforms06112002.asp
Here is the code:
public ref class Form1 : public System::Windows::Forms::Form
{
...
....
....
....
private: System::Void button1_Click(System::Object^ sender,
System::EventArgs^ e)
{
CalcPiDelegate ^calcPi = gcnew CalcPiDelegate(this, &Form1::calcPi);
calcPi->BeginInvoke(1, nullptr, nullptr);
}
private: delegate System::Void CalcPiDelegate(int max);
private: System::Void calcPi(int max)
{
ShowProgress(0, max);
for (int i = 0; i < max; i++)
{
ShowProgress(i, max);
}
}
private: delegate System::Void ShowProgressDelegate(int i, int max);
private: System::Void ShowProgress(int i, int max)
{
if (richTextBox1->InvokeRequired == false)
{
richTextBox1->AppendText(Convert::String(i) +
Environment::NewLine);
progressBar1->Maximum = max;
progressBar1->Value = i;
}
else
{
ShowProgressDelegate ^progDelegate = gcnew
ShowProgressDelegate(this,&Form1::ShowProgress);
cli::array<int> ^args = gcnew cli::array<int>(2);
args[0] = i;
args[1]= max;
BeginInvoke(progDelegate,args);
}
}
};
The BeginInvoke call causes the following exception:
An unhandled exception of type
'System.Reflection.TargetParameterCountException' occurred in mscorlib.dll
Additional information: Parameter count mismatch.
Unfortunately I can not determine why this error occurs. Any help or
hint is greatly appreciated.
Regards
To get an understanding of UI threads in C++/CLI, I attempted to
duplicate the following C# example:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/html/winforms06112002.asp
Here is the code:
public ref class Form1 : public System::Windows::Forms::Form
{
...
....
....
....
private: System::Void button1_Click(System::Object^ sender,
System::EventArgs^ e)
{
CalcPiDelegate ^calcPi = gcnew CalcPiDelegate(this, &Form1::calcPi);
calcPi->BeginInvoke(1, nullptr, nullptr);
}
private: delegate System::Void CalcPiDelegate(int max);
private: System::Void calcPi(int max)
{
ShowProgress(0, max);
for (int i = 0; i < max; i++)
{
ShowProgress(i, max);
}
}
private: delegate System::Void ShowProgressDelegate(int i, int max);
private: System::Void ShowProgress(int i, int max)
{
if (richTextBox1->InvokeRequired == false)
{
richTextBox1->AppendText(Convert::String(i) +
Environment::NewLine);
progressBar1->Maximum = max;
progressBar1->Value = i;
}
else
{
ShowProgressDelegate ^progDelegate = gcnew
ShowProgressDelegate(this,&Form1::ShowProgress);
cli::array<int> ^args = gcnew cli::array<int>(2);
args[0] = i;
args[1]= max;
BeginInvoke(progDelegate,args);
}
}
};
The BeginInvoke call causes the following exception:
An unhandled exception of type
'System.Reflection.TargetParameterCountException' occurred in mscorlib.dll
Additional information: Parameter count mismatch.
Unfortunately I can not determine why this error occurs. Any help or
hint is greatly appreciated.
Regards