欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

异步调用进度条窗体弹出加载数据

程序员文章站 2023-11-07 15:43:52
异步调用进度条窗体弹出 public partial class LoadProgressBar : Form { int losttime = 0; /// /// 是否可以关闭窗体 /// public bool ClosedFlag = false; ......

异步调用进度条窗体弹出

 

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();
}
}

}