我遇到了析构函数问题。这是重现问题的代码:
class DPDemo : DependencyObject
{
public DPDemo()
{
}
~DPDemo()
{
Console.WriteLine(this.Test); // Cross-thread access
}
public int Test
{
get { return (int)GetValue(TestProperty); }
set { SetValue(TestProperty, value); }
}
// Using a DependencyProperty as the backing store for Test. This enables animation, styling, binding, etc...
public static readonly DependencyProperty TestProperty =
DependencyProperty.Register("Test", typeof(int), typeof(DPDemo), new PropertyMetadata(0));
}
当析构函数运行时,我在行上得到一个 InvalidOperationException get {SetValue...
。是否有推荐的方法从析构函数或其他线程中读取依赖属性?