c# - 调用 SolidColorBrush
问题描述
我怎么能调用,所以我不会得到以下错误?
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();
}));
}
解决方案
您可以使用control.Dispatcher.CheckAccess()来检查当前线程是否拥有该控件。如果它确实拥有它。否则使用此方法:
this.Dispatcher.Invoke(() =>
{
...// your code here.
});
推荐阅读
- c# - 尝试添加到实体框架中的父级时,我的子实体为空
- android - android 10 删除文件夹
- python - 不停止打印
- r - 无法将 R 数据放入数据框中
- html - 如何停止动画将我的页脚向下移动
- c - 在C二叉树中插入函数?
- eclipse - 一个或多个约束没有得到满足。无法安装项目方面 Java 1.8。此项目方面的某些版本已安装
- macos - 如何创建一个更改空投文件目标文件夹的苹果脚本?
- python - 将数据从 MongoDB 游标加载到 pandas Dataframe 的更快方法
- javascript - 应用程序组件看不到 index.html 中声明的条带元素?