日期:2014-05-17  浏览次数:21108 次

多线程中,有线程不执行的问题
问题:三个线程,其中第一个线程始终不执行程序.
代码如下:
        private delegate void del();

        private void clearControls()
        {
            
            Thread balance = new Thread(new ThreadStart deleteDataColumnsOfBalance));
            balance.Start();
            Thread income = new Thread(new ThreadStart(deleteDataColumnsOfIncome));
            income.Start();
            Thread cash = new Thread(new ThreadStart(deleteDataColumnsOfCash));
            cash.Start();


            while (!balance.IsAlive&&!income.IsAlive&&!cash.IsAlive) { Thread.Sleep(10); }
            balance.Abort();
            balance.Join();
            income.Abort();
            income.Join();
            cash.Abort();
            cash.Join();
        }

        /// <summary>
        /// 自定义方法:删除DataGridView控件列
        /// </summary>
        /// <param name="dgv">指定DataGridView控件</param>
        private void deleteDataColumnsOfBalance()
        {
            if (dgvBalance.InvokeRequired)
            {
                del d = new del(deleteDataColumnsOfBalance);
                dgvBalance.Invoke(d);
            }
            else
            {
                for (int i = dgvBalance.Columns.Count - 1; i > 1; i--)
                {
                    dgvBalance.Columns.Remove(dgvBalance.Columns[i]);
                    pgbar.PerformStep();