---
title: "ASP.NET kills my background thread?"  
description: "ASP.NET kills my background thread?"  
author: "Anonymous User"  
published: 2014-11-17  
updated: 2014-11-17  
canonical: https://www.mindstick.com/forum/12618/asp-dot-net-kills-my-background-thread  
category: "asp.net"  
tags: ["asp.net"]  
reading_time: 1 minute  

---

# ASP.NET kills my background thread?

I have the following [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) in my codebehind ([aspx.cs](https://www.mindstick.com/forum/172/how-v-insert-data-into-table-and-display-into-gridview-in-aspx-cs-file-with-out-using-wizard)):

```
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\

## Replies

### Reply by Sumit Kesarwani

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


---

Original Source: https://www.mindstick.com/forum/12618/asp-dot-net-kills-my-background-thread

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
