1. 问题:如果跨线程操作UI控件,则会报出如下错误:
2. 解决:
(1)BeginInvoke 异步操作
App.Current.Dispatcher.BeginInvoke(new Action(() =>
{
//操作代码
}));
(2)Invoke 同步操作
App.Current.Dispatcher.Invoke(new Action(() =>
{
//操作代码
}));
App.Current.Dispatcher.BeginInvoke(new Action(() =>
{
//操作代码
}));
App.Current.Dispatcher.Invoke(new Action(() =>
{
//操作代码
}));