WPFでWindows FormのApplication.DoEventsメソッドと同様に長時間かかる処理の間にUIのイベントを処理させるには、下記のように行う。(MSDNより)
[SecurityPermissionAttribute(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)]
public void DoEvents()
{
DispatcherFrame frame = new DispatcherFrame();
Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background,
new DispatcherOperationCallback(ExitFrame), frame);
Dispatcher.PushFrame(frame);
}public object ExitFrame(object f)
{
((DispatcherFrame)f).Continue = false;return null;
}
Last 5 posts in .Net Framework
- 同一サーバーへの同時接続数を構成ファイルで設定するには - May 23rd, 2012
- VSTO セットアッププログラムからインストールしたAddinのApp.configが読み込まれない場合 - May 7th, 2012
- CanExecuteのTrue,Falseを変更してもコマンド実行の可否がGUIに反映されない場合には - April 12th, 2011