用visual studio 2005做了一个C#的多线程程序,调试的时候,如果断点在主线程,没有问题,但如果断点设在线程里面,运行到断点时,visual studio 会停止反应,大概10秒以后才会恢复,但按下“F10”以后,程序根本就不断,直到程序第二次到达断点,才正常。请问有没有解决的办法?
谢谢

解决方案 »

  1.   

    多线程调试起来比较的麻烦。设置断点不是个好办法。你可以尝试在控制台上输出。或者写log 文件。。
      

  2.   

    我使用vs2005没有遇到过这样的问题。using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Threading;namespace MultiThreads
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private void Form1_Load(object sender, EventArgs e)
            {
                Thread t = new Thread(Test);
                
                t.Start();
                MessageBox.Show("Main thread");
            }
            private void Test()
            {
                string tmp = "Background thread";
               
                MessageBox.Show(tmp);
                
            }    }
    }
      

  3.   

    我的代码:private void button_copy_Click(object sender, EventArgs e)
    {
    ...
                CCopyParam pCopy = new CCopyParam(m_strSourceFile, m_strDestFile, 0, 0);
                Thread tCheck = new Thread(new ParameterizedThreadStart(ThreadCheckFile));
                tCheck.Start(pCopy);
    ...
    }public void ThreadCopyFile(Object pCopy)
    {
    ...
               CallBackMessage(2, 0, iStart, iSize);
    ...
    }public delegate void delegateReturn(int iThread, int iRtn, long iStart, long iSize);private void CallBackMessage(int iThread, int iRtn, long iStart, long iSize)
    {
                delegateReturn dReturn = new delegateReturn(MainDispatchMessage);
                Object[] oParam = new Object[4];
                oParam[0] = (Object)iThread;
                oParam[1] = (Object)iRtn;
                oParam[2] = (Object)iStart;
                oParam[3] = (Object)iSize;
                Invoke(dReturn, oParam);
    }private void MainDispatchMessage(int iThread, int iRtn, long iStart, long iSize)
    {
    ...
             switch (iRtn)
             {
              case 1: ...
                  // 断点在这里
    ...
              }
    ...
    }