如何调用才不会得到以下错误?
System.InvalidOperationException:
调用线程无法访问此对象,因为另一个线程拥有它.
// Method 1
if (((SolidColorBrush)RRefresh.Fill).Color == CustomGreen.Color && Foldername == string.Empty)
{
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
Driver.Navigate().Refresh();
}));
}
// Method 2
if (Driver != null && ((SolidColorBrush)RRefresh.Fill).Color == CustomGreen.Color)
{
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
Driver.Navigate().Refresh();
}));
}发布于 2018-05-29 06:42:18
您可以使用control.Dispatcher.CheckAccess()检查当前线程是否拥有该控件。如果它拥有它。否则,请使用此方法:
this.Dispatcher.Invoke(() =>
{
...// your code here.
});https://stackoverflow.com/questions/50577736
复制相似问题