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
- CanExecuteのTrue,Falseを変更してもコマンド実行の可否がGUIに反映されない場合には - April 12th, 2011
- WebRequestの最大接続数を設定ファイルで変更するには - April 9th, 2011
- WebRequestの最大同時接続数を変更するには - April 5th, 2011