在asp.net中禁用计时器后,计时器在asp.net中没有停止

时间:2015-03-28 11:06:01

标签: c# asp.net ajax timer

我在ASP.NET网页中设置了计时器。然后我在完成该过程后禁用了计时器,但计时器仍在运行。

static bool _end;
protected void UpdateTimer_Tick(object sender, EventArgs e)
{
    if (_end)
    {
        _end = false;                     
        UpdateTimer.Enabled = false;                    
        Download();
    }
}

这是点击事件:

protected void btnStart_Click(object sender, EventArgs e)
{            
    StringBuilder threadBuilder = new StringBuilder();
    ProgressBar1.Visible = true;
    pReadytoDown.Visible = true;
    _end = false;
    Progress progress = ProgressBar1.Progress;

    Thread thread = new Thread(() =>
    {
        _end= Start(progress);
        _builder = threadBuilder;
    });
    thread.Start();
}

这是下载文件的乐趣:

public void Download()
{
    string path = Server.MapPath("~/") + "ExcelFiles\\Sample.xlsx";
    Response.ClearContent();
    //context.Response.ClearHeaders();       
    Response.BufferOutput = true;
    Response.Charset = "";
    Response.AddHeader("content-disposition", "attachment;filename=ExportData1.xlsx");
    Response.ContentType = "application/vnd.xlsx";
    Response.WriteFile(path);
    Response.Flush();
    Response.End();
    return;
}

1 个答案:

答案 0 :(得分:0)

尝试这个

     if(IsPostBack)
                {
//first time timer1 has default value as 60000 = 1 sec then 2nd time it value will be 10 min
                    timer1.Interval = 600000; 
                    ViewState["countet"] = 600000;
                }