【发布时间】:2011-11-07 23:01:06
【问题描述】:
我有一个来自 wpf 扩展工具包的 BusyIndicator,我正在运行一个需要一段时间才能完成的函数。如果我在单独的线程中运行耗时的任务,我会收到 NotSupportedException,因为我正在尝试将对象从那个不同的线程插入到 ObservableCollection 中。如果可能的话,我真的不想花很多时间重构代码......有没有办法可以在单独的线程中设置指示器的可见性?
编辑
ThreadStart start = delegate()
{
System.Windows.Application.Current.Dispatcher.Invoke((Action)(() =>
{
IsBusy = true;
}));
};
new Thread(start).Start();
longRunningFunction();
这对我也不起作用。
【问题讨论】:
-
我编辑了我的答案,为您提供解决方案。
标签: wpf multithreading busyindicator