如何使这一个美丽和正确的代码

本文关键字:代码 美丽 一个 何使这 | 更新日期: 2023-09-27 18:06:37

如何使这是一个美丽和正确的代码?

启用父窗口

创建线程进度条。

代码

并关闭进度条

var iCount = 3;
while(iCount>0)
{
    if (myProgressBar!= null && myProgressBar.IsHandleCreated)
    {
        iCount = -1;
        break;
    }
    iCount--;
    Thread.Sleep(1000);
}
if (iCount != -1)
    return false;//MessageBox  
所有功能:

this.Enabled = false;
MyProgressBar myProgressBar = null;
    try
    {
        var thread2 = new Thread(delegate()
        {
            myProgressBar = new MyProgressBar(this);
            myProgressBar.ShowDialog();
        });
        thread2.Start();
        Thread.Sleep(100);
        var iCount = 3;
        while(iCount>0)
        {
            if (myProgressBar!= null && myProgressBar.IsHandleCreated)
            {
                iCount = -1;
                break;
            }
            iCount--;
            Thread.Sleep(1000);
        }
        if (iCount != -1)
            return false;//MessageBox
        for (int i = 0; i < list.Count; i++)
        {
            //more code
        }

    }
    catch (Exception e)
    {
    }
    finally
    {
        myProgressBar.CloseMe();
        this.Enabled = true;
    }

如何使这一个美丽和正确的代码

您看过BackgroundWorker班吗?