我的进度条没有得到后台工作者的更新。它在线程完成后更新

时间:2013-05-11 12:27:31

标签: c# directx

我正在使用后台工作程序进行处理,同时我需要更新进度条。 我使用backgroundworker.ReportProgress更新progressBar值,但值会更新给用户  后台线程完成后我需要在后台工作程序运行时显示进度条更新。

我的代码是

    public bool IsClosed()
    {
      bool profileClosed = false;           
        for (int i = 0; i < originalEntityList.Count; i++)
        {
            if (originalEntityList[i] is Core.DatabaseServices.Point)
                entityList.RemoveAt(i);
        }         
        CoreApp.ModelSpace.customProgressValue = 0;
        CoreApp.ModelSpace.TotalPercentage = OriginalEntityList.Count;          

        if (!CoreApp.ModelSpace.backgrdWorker.IsBusy)
            CoreApp.ModelSpace.backgrdWorker.RunWorkerAsync(); 

        CoreApp.ModelSpace.IndicateProgress(true, new EventArgs()); 

        if (!profileClosed)
                UtilitiesLocalization.ShowMessage(UtilitiesLocalization.ProfileNotClosedMessage, UtilitiesLocalization.InvalidProfileTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning);

        return profileClosed;
    }  



     private void backgrdWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
    { 
        if (!checkProfileInvalid)
        {
            Thread overlapThread = new Thread(new ThreadStart(CheckOverlapEntities)); 
            overlapThread.IsBackground = true;
            overlapThread.Start();
            overlapThread.Join();
        }
    }  




    public static bool CheckOverlapEntities()
    {
        OverlapedEntities.Clear();
        OriginalCollection = new List<Entity>(EntityCollection);
        TempCollection = new List<Entity>(EntityCollection);

        List<Thread> threadList = new List<Thread>();
        for (int id = 0; id < TempCollection.Count; id++)
        {
            CoreApp.ModelSpace.backgrdWorker.ReportProgress(id+1);          

            Entity currentEntity = TempCollection[id];
            if (currentEntity is PolyLine3d && (currentEntity as PolyLine3d).IsClosed) continue;

            Thread tempThread = new Thread(new ParameterizedThreadStart(FindOverlapInParallel));
            threadList.Add(tempThread);
            tempThread.Start(currentEntity);

            if (threadList.Count == MaxThread)
            {
                for (int i = 0; i < threadList.Count; i++)
                {
                    threadList[i].Join();
                    if (checkProfileInvalid) break;
                }
                threadList = new List<Thread>();
            }           
        }                     
        CoreApp.ModelSpace.backgrdWorker.ReportProgress(100);
        if (OverlapedEntities.Count > 0)
            return true;
        return false;
    }  




    void backgrdWorker_ProgressChanged(object sender, System.ComponentModel.ProgressChangedEventArgs e)
    {             
            colorProgressBar1.Value = e.ProgressPercentage;
            colorProgressBar1.PerformStep(); 
           if (e.ProgressPercentage == colorProgressBar1.Maximum)             
                colorProgressBar1.Value = 0;                                     
    }

先谢谢..

0 个答案:

没有答案
相关问题