首页 > 代码库 > wpf 常见死锁方式

wpf 常见死锁方式

 Thread tr0 = new Thread(new ParameterizedThreadStart((obj1) =>            {                lock (aaa)                {                    Thread.Sleep(3000);                    this.Dispatcher.Invoke(new Action(() =>                    {                        Thread.Sleep(3000);                    }));                }            }));            tr0.IsBackground = true;            tr0.Start();            Thread.Sleep(3000);            lock (aaa)            {                Thread.Sleep(3000);            }

 

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

wpf 常见死锁方式