BackgroundWorker我该怎么debug?
我debug去单步跟踪的时候,光标跳来跳去的,我怎么追踪,请教下有没好办法

解决方案 »

  1.   

    先在单线程环境下调好,再写到BackgroundWorker呗。
      

  2.   

    本帖最后由 bdmh 于 2012-06-14 11:07:04 编辑
      

  3.   

    BackgroundWorker.RunWorkerAsync();
    后加上句
    Thread.Sleep(-1);
    先把主线程塞住,在 DoWork 事件的方法开始处断点,DoWork 调试正常后再把 Sleep 去掉让它们并行。
      

  4.   


            private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
            {
                int iRet = -1;            while (!backgroundWorker1.CancellationPending)
                {
                    short[] PriShortChamberRecipeArray = GetRecipeDataFromXml(@"C:\HuaYing\test.xml");
                    iRet = axActQJ71E71TCP1.WriteDeviceBlock2("R0", PriShortChamberRecipeArray.Length, ref PriShortChamberRecipeArray[0]);
                }
       
            }        private short[] GetRecipeDataFromXml(string filename)
            {
                DataTable table = new DataTable();
                table.ReadXml(filename);
                //this._lpsData = new short[(table.Rows.Count + 1) * 25];
                short[] PriChamberRecipeArray = new short[(table.Rows.Count + 1) * 25];            for (int i = 0; i < table.Rows.Count; i++)
                {
                    object[] objArr = table.Rows[i].ItemArray;                for (int j = 0; j < objArr.Length; j++)
                    {
                        if (objArr[j] == System.DBNull.Value)
                        {
                            if (j >= 1 && j <= 12)
                                objArr[j] = 1;
                            else
                                continue;
                        }
                        //this._lpsData[i * 25 + j] = short.Parse(objArr[j].ToString());
                        PriChamberRecipeArray[i * 25 + j] = short.Parse(objArr[j].ToString());                }
                }
                return PriChamberRecipeArray;
            }        private void button3_Click(object sender, EventArgs e)
            {
                int iRet = -1;            while (true)
                {
                    System.Threading.Thread.Sleep(100);
                    short[] PriShortChamberRecipeArray = GetRecipeDataFromXml(@"C:\HuaYing\test.xml");
                    iRet = axActQJ71E71TCP1.WriteDeviceBlock2("R0", PriShortChamberRecipeArray.Length, ref PriShortChamberRecipeArray[0]);            }
            }
    这两段代码都是用的硬件开发包自带的一个函数WriteDeviceBlock2向硬件发送数据。在异步程序里面发送数据就有问题,实际发送的数据并不是PriShortChamberRecipeArray,是比较随机的数据,太奇怪了,都只调用一个方法而已,不解原因
      

  5.   

    你的业务处理的几个程序,应该提取到一个BLL层工程项目中,使用console程序来测试它。