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);
            }

 

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

相关文章
相关标签/搜索