Visual Studio 2015 Debug doesn't work in multithread application

假装没事ソ 提交于 2019-12-02 22:16:34

I've experienced similar issues with VS2015 freezing (indefinitely) whilst debugging a multi thread WinForms application.

I had no problems debugging the same code in VS2013.

The problem appears to go away when I disable the VS hosting process (Project -> Properties -> Debug -> Enable the Visual Studio hosting process).

Hope that works for others.

After i checked "use managed compatibility mode" in options-debugging-general, thread debugging seems to work.

I had breakpoints in 2 different threads and Visual Studio was bouncing from one to the other as I stepped through. Eventually it froze with (Not Responding) in the title bar.

If I limited the breakpoints to just one thread, I would not experience the problem.

I had a similar issue. The other answers to this question did not resolve the issue for me, but they pointed me to the right direction. Apparently I had the Release configuration selected, instead of Debug.

After annoying hours, the answer of @Haggisatonal was it for me. Thank you very much!

The problem appears to go away when I disable the VS hosting process (Project -> Properties -> Debug -> Enable the Visual Studio hosting process).

but

"Tools -> Options -> Debugging -> General -> Enable property evaluation and other implicit function calls"

like in a nother Ticket, was not the resolution for me, maybe it helps temporairly others

I had the problem of visual studio 2008 freeze even after disabling the hosting process. What seems to be working for me is disabling address level debugging.

(VS2008) Tools (menu) -> Options -> Debugging -> General -> (uncheck) Enable address-level Debugging.

I suggest that you use a combilation of a Timer and WaitHandle in your code instead of the for loop that causes high CPU usage. I made a simple change to your code to ease the CPU usage. Hope that help.

    public partial class Form1 : Form
    {
        EventWaitHandle _waitHandle ;
        System.Timers.Timer _timer; 
        public Form1()
        {
            InitializeComponent();
            _waitHandle = new EventWaitHandle(false, EventResetMode.AutoReset);
            _timer = new System.Timers.Timer();
            _timer.Interval = 100;
            _timer.Elapsed += OnTimerElapsed;
            _timer.AutoReset = true;

        }

        private void OnTimerElapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            _waitHandle.Set();
        }

        void FuncAsync(IProgress<int> progress)
        {
            _timer.Start();
            int percent = 0;
            while (percent <= 100)
            {
                if (_waitHandle.WaitOne())
                {
                    progress.Report(percent);
                    percent++;
                }
            }
            _timer.Stop();

        }
        void FuncBW(BackgroundWorker worker)
        {
            _timer.Start();
            int percent = 0;
            while (percent <= 100)
            {
                if (_waitHandle.WaitOne())
                {
                    worker.ReportProgress(percent);
                    percent++;
                }
            }
            _timer.Stop();
        }



        void FuncThread()
        {
            _timer.Start();
            int percent = 0;
            while (percent <= 100)
            {
                if (_waitHandle.WaitOne())
                {
                    if (this.InvokeRequired)
                    {
                        this.Invoke((Action)delegate { label1.Text = percent.ToString(); });
                    }
                    else
                    {
                        label1.Text = percent.ToString();
                    }
                    percent++;
                }
            }
            _timer.Stop();
        }


        ... your other code
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!