1

I have a WinForms application, and wanted to add some nice WPF controls, one of them being an 'indeterminate' progress bar.. which just animates nicely until I tell it to stop.

I have done this, and was racking my brains as to why it wasn't animating (changing the value of the progress bar).

I eventually tried showing my form (containing the ElementHost) modally, and hey presto, it animates, but I want to show the form non-modally, as I want to continue processing behind the scenes.

Is there some kind of setting that tells the ElementHost window to continue 'animating'?

Thanks Rich.

4

2 に答える 2

0

これを行うには多くの方法がありますが、最も簡単な方法は、時間のかかるタスクにバックグラウンド ワーカーを使用することです。Backgroundworker には、進行状況を報告するイベントがあります。このイベントを処理し、ハンドラーでプログレスバーの値を変更します。メイン スレッドで作業を行っているときにメイン スレッドでアニメーションを表示するだけでは、正しく動作しません。
もう 1 つの方法として、DoEvents 関数を実装して呼び出すことをお勧めします (ただし、健全なアプリにはお勧めしません)。プログレスバーを更新したい場合は、メインスレッドで... DoEvents 実装のリンクは次のとおりです
。MSDN DoEvents
の提案 ただし、最初のアプローチを強くお勧めします

于 2011-12-13T10:22:13.300 に答える
0

上記のコメントで述べたように、解決策は別のスレッドで処理を実行することです。これにより、.net メイン GUI スレッドが処理を実行し、プログレス バーをアニメーション化できます。

于 2012-01-25T19:21:55.433 に答える