开发者

How to make this a beautiful and correct the code?

开发者 https://www.devze.com 2023-03-30 16:47 出处:网络
How to make this a beautiful and correct the code? I enable parent window. Create thread progress bar. perform code

How to make this a beautiful and correct the code?

I enable parent window.

Create thread progress bar.

perform code

and close the progress bar

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

all function:

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;//Mess开发者_StackOverflow中文版ageBox

        for (int i = 0; i < list.Count; i++)
        {
            //more code
        }


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

    }


Have you seen the BackgroundWorker class?

It will simplify your logic greatly.

0

精彩评论

暂无评论...
验证码 换一张
取 消