private
void
btnWrite_Click(
object
sender, EventArgs e)
{
int
taskCount = 10000;
this
.pgbWrite.Maximum = taskCount;
this
.pgbWrite.Value = 0;
DataWrite dataWrite =
new
DataWrite();
dataWrite.UpdateUIDelegate += UpdataUIStatus;
dataWrite.TaskCallBack += Accomplish;
Thread thread =
new
Thread(
new
ParameterizedThreadStart(dataWrite.Write));
thread.IsBackground =
true
;
thread.Start(taskCount);
}
private
void
UpdataUIStatus(
int
step)
{
if
(InvokeRequired)
{
this
.Invoke(
new
AsynUpdateUI(
delegate
(
int
s)
{
this
.pgbWrite.Value += s;
this
.lblWriteStatus.Text =
this
.pgbWrite.Value.ToString() +
"/"
+
this
.pgbWrite.Maximum.ToString();
}), step);
}
else
{
this
.pgbWrite.Value += step;
this
.lblWriteStatus.Text =
this
.pgbWrite.Value.ToString() +
"/"
+
this
.pgbWrite.Maximum.ToString();
}
}
private
void
Accomplish()
{
MessageBox.Show(
"任务完成"
);
}