wpf 常见死锁方式

时间:2021-08-24 14:11:08
 Thread tr0 = new Thread(new ParameterizedThreadStart((obj1) =>
{
lock (aaa)
{
Thread.Sleep();
this.Dispatcher.Invoke(new Action(() =>
{
Thread.Sleep();
}));
}
}));
tr0.IsBackground = true;
tr0.Start(); Thread.Sleep();
lock (aaa)
{
Thread.Sleep();
}

在线程里面访问主线程,主线程和线程共用一把锁互相等待导致死锁。