异步调用进度条窗体弹出加载数据
异步调用进度条窗体弹出
public partial class loadprogressbar : form
{
int losttime = 0;
/// <summary>
/// 是否可以关闭窗体
/// </summary>
public bool closedflag = false;
public loadprogressbar()
{
initializecomponent();
}
public void setprogressmaxvalue(int value, string name)
{
progressbar1.maximum = value;
progressbar1.value = 0;
namelab.text = name;
losttime = 0;
console.writeline("maximum:" + value);
}
public void setvalue(int value, int totalvalue)
{
try
{
losttime = 0;
this.progressbar1.begininvoke(new action(() =>
{
progressbar1.maximum = totalvalue;
int tempvalue = progressbar1.value + value;
if (tempvalue < progressbar1.maximum)
{
speedlab.text = tempvalue.tostring("d2") + "/" + totalvalue.tostring("d2");
progressbar1.value = tempvalue;
}
console.writeline("tempvalue:" + tempvalue);
}));
}
catch
{ }
}
private void loadprogressbar_formclosing(object sender, formclosingeventargs e)
{
if (closedflag == false)
{
if (losttime > 30)
{
this.dialogresult = dialogresult.cancel;
return;
}
if (messagebox.show("正在导出文件,是否要中断?", "提示", messageboxbuttons.yesno, messageboxicon.question) == dialogresult.yes)
{
this.dialogresult = dialogresult.cancel;
}
else
{
e.cancel = true;
//this.dialogresult = dialogresult.cancel;
}
}
else
{
this.dialogresult = dialogresult.ok;
}
}
private void closed_pic_click(object sender, eventargs e)
{
this.close();
}
private void timer1_tick(object sender, eventargs e)
{
losttime++;
if (losttime > 30)
{
this.close();
}
}
}
上一篇: 锡纸土豆做法简单,还有一定的营养功效