View Code
this
.button1.Content
=
"
正在计算
"
;
Action action = new Action(() => {
System.Threading.Thread.Sleep( 3000 );
this .Dispatcher.BeginInvoke( new Action(() =>
{
this .button1.Content = " 计算完毕 " ;
}), System.Windows.Threading.DispatcherPriority.SystemIdle, null );
});
action.BeginInvoke( null , null );
Action action = new Action(() => {
System.Threading.Thread.Sleep( 3000 );
this .Dispatcher.BeginInvoke( new Action(() =>
{
this .button1.Content = " 计算完毕 " ;
}), System.Windows.Threading.DispatcherPriority.SystemIdle, null );
});
action.BeginInvoke( null , null );
本文介绍了一种在WPF应用程序中防止界面卡顿的方法。通过将耗时操作放入后台线程,并使用Dispatcher来更新UI元素的状态,确保了用户体验的流畅性。
781

被折叠的 条评论
为什么被折叠?



