ASP.NET KILLS MY BACKGROUND THREAD?

Ankit Singh

Total Post:341

Points:2389
Posted by  Ankit Singh
 995  View(s)
Ratings:
Rate this:

I have the following code in my codebehind (aspx.cs):

protected void button1_Click(object sender, EventArgs e)
{
    new Thread(delegate() {
        try
        {
            Thread.Sleep(30000); //do nothing for 30 seconds
        }
        catch (Exception ex)
        {
            //I AWLAYS get a ThreadAbortException here
            //in about 1 second WHY!?!??!
        }
    }).Start();
}

Please help me

  1. Sumit Kesarwani

    Post:378

    Points:2694
    Re: ASP.NET kills my background thread?

    Hi Ankit, 

    try this :
    protected void button1_Click(object sender, EventArgs e)
    {
        var bg = new BackgroundWorker();
        bg.DoWork +=delegate
        {
            try
            {
                Thread.Sleep(10000); //do nothing for 10 seconds
            }
            catch(Exception ex)
            {
                //no excpeiton is thrown
            }
        };
        bg.RunWorkerAsync();
    }

    Hope this will solve your problem

      Modified On Apr-06-2018 06:31:32 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!