In my Visual Studio solution I have UI implemented in C# and some code implemented in native C++.
I use BackgroundWorker class to implemenent reporting progress of execution long operation.
How can I use BackgroundWorker to report progress from my native C++ code?
In other words, how can I rewrite the C# code below to native C++ and call obtained C++ code from C#?
If it is not possible to rewrite the code below directly, it could be good to know about other equivalent solutions. Thanks.
class MyClass
{
public void Calculate(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
for (int i = 0; i < StepCount; i++)
{
if (worker.CancellationPending)
{
e.Cancel = true;
break;
}
// code which handles current iteration here
worker.ReportProgress((i + 1) * 100 / StepCount,
"Report progress message");
}
}
}
Example follows.
It was tested on x86 C# and native Visual C++:
CppLayer.h:
CppLayer.cpp:
C# class which interoperate with C++ code:
Following links might be useful: