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

相關文章
相關標籤/搜索