は、ここではイベント
C++:
int progressvalue;
extern "C" __declspec(dllexport) void __cdecl LongRunningMethod(int seconds)
{
cout << "Started" << endl;
progressvalue = 0;
for (size_t i = 0; i < seconds; i++)
{
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
progressvalue = (seconds - ((double)seconds/ (double)i))*10;
cout << "Progress value in c++: " << progressvalue << endl;
}
cout << "Completed" << endl;
}
extern "C" __declspec(dllexport) int __cdecl GetProgressUpdate()
{
return progressvalue;
}
せずにそれを行うに簡単な方法は、C# C#で、それを消費する方法である:
private void button_Click(object sender, RoutedEventArgs e)
{
var task = Task.Factory.tartNew(() => {
NativeMethods.LongRunningMethod(10);});
Task.Factory.StartNew(() =>
{
while (!task.IsCompleted)
{
Dispatcher.Invoke(() =>
{
var val = NativeMethods.GetProgressUpdate();
ProgressBarMain.Value = val;
Thread.Sleep(100);
});
}
});
}
はあなたの提案のために、デビッド・ヨー、ありがとうございました。はい、私は%completeを扱うためのパラメータを取るManagedメソッドを持っています。また、長時間実行するためのパラメータを持つこともできます。しかし、私はいくつかの小さなスニペットを共有することができれば感謝します。 – user5579704
これを実装する際に手を入れてください。具体的な問題がある場合は、具体的に質問を投稿してください。この種の問題には、一般的なヘルプがたくさんあります。 –