关于这一点,我阅读了很多解决方案,但是不幸的是,我不知道我该如何在代码中确切地做到这一点。下面是我的代码。
*我的代码要做的是对流程进行分块以在每个流程上提供确切的状态。每个进程将被登录到文件中。但是,在到达最后一个要禁用我的计时器的步骤之后,就好像它在整个过程完成后几分钟从头到尾再次运行整个过程一样。我的计时器在updatepanel以及列表框和GIF加载中*
protected void GenerateBtn_Click(object sender, EventArgs e)
{
StartLongRunningTask();
lblDescription.Text = "";
lstStatusMessage.Visible = true;
lstStatusMessage.Items.Clear();
this.imgProgress.Visible = true;
this.mainTimer.Enabled = true;.
}
private void StartLongRunningTask()
{
this.Application["MaxIndex"] = "4";
this.Application["Counter"] = "0";
this.Application["FilenameSS"] = "";
this.Application["recordCount"] = "0";
}
protected void mainTimer_Tick(object sender, EventArgs e)
{
int maxIndex = Convert.ToInt32(this.Application["MaxIndex"]);
int counter = Convert.ToInt32(this.Application["Counter"]);
if (counter == 0)
{
lblDescription.Text = "[" + DateTime.Now.ToString("MM/dd/yyyy h:mm tt") + "] Selected date verified. Checking possible candidate(s) on the selected date.";
lstStatusMessage.Items.Add(lblDescription.Text);
this.Application["Counter"] = ++counter;
}
else if (counter == 1)
{
lblDescription.Text = "[" + DateTime.Now.ToString("MM/dd/yyyy h:mm tt") + "] Candidate(s) found. Preparing your per Store Report.";
lstStatusMessage.Items.Add(lblDescription.Text);
this.Application["Counter"] = ++counter;
}
else if (counter == 2)
{
GeneratePerStore();
lblDescription.Text = "[" + DateTime.Now.ToString("MM/dd/yyyy h:mm tt") + "] per Store Report created successfully. Preparing now your Summary Report.";
lstStatusMessage.Items.Add(lblDescription.Text);
this.Application["Counter"] = ++counter;
}
else if (counter == 3)
{
lblDescription.Text = "[" + DateTime.Now.ToString("MM/dd/yyyy h:mm tt") + "] Summary Report created successfully.";
lstStatusMessage.Items.Add(lblDescription.Text);
this.Application["Counter"] = ++counter;
}
else if (counter == 4)
{
lblDescription.Text = "[" + DateTime.Now.ToString("MM/dd/yyyy h:mm tt") + "] Process complete! Thank you!";
lstStatusMessage.Items.Add(lblDescription.Text);
this.Application["Counter"] = ++counter;
}
else if (counter == 5)
{
lblDescription.Text = "";
this.lblDescription.Visible = false;
this.imgProgress.Visible = false;
this.mainTimer.Interval = int.MaxValue;
this.mainTimer.Enabled = false;
}
string message = string.Format(this.lblDescription.Text);
string Filename = Server.MapPath("Files") + "\\Logs.txt";
if (!File.Exists(Filename))
{
StreamWriter txtFile = File.CreateText(Filename);
txtFile.Close();
txtFile = File.AppendText(Filename);
txtFile.WriteLine(message);
txtFile.Close();
}
else
{
message += Environment.NewLine;
File.AppendAllText(Filename, message);
}
//end
}
这是我在这里的第一篇文章,也是我对此致以最深深的歉意。希望你们能帮助我。 :(