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

异步调用进度条窗体弹出

public partial class LoadProgressBar : Form
{
int losttime = 0;
///
/// 是否可以关闭窗体
///
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();
}
}

}
深圳网站建设www.sz886.com

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值