如何使这段代码变得美观且正确?
如何使这段代码变得美观且正确?
我启用父窗口。
创建线程进度条。
执行代码
并关闭进度条
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;
}
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;//MessageBox
for (int i = 0; i < list.Count; i++)
{
//more code
}
}
catch (Exception e)
{
}
finally
{
myProgressBar.CloseMe();
this.Enabled = true;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您见过
BackgroundWorker
类?它将大大简化你的逻辑。
Have you seen the
BackgroundWorker
class?It will simplify your logic greatly.