What happens if you start a background thread to execute just before ASP.NET finishes processing your page?

What happens if I turn off the thread to complete a lengthy process right before the ASP.NET page life cycle ends? Will ASP.NET runtime kill a thread? Could this lead to undefined behavior?

Here's a sample code that rotates the background thread in the Page_Load event. Is this a safe thing?

protected void Page_Load(object sender, EventArgs e)
{
    Thread newThread = new Thread(new ThreadStart(SomeLongRunningMethod));
    newThread.IsBackground = true;
    newThread.Start();
}

private void SomeLongRunningMethod()
{
    // some long running process goes here...
}
+5
source share
4 answers

, . , , .

, .

, , , , , , .

+1

som / ffmpeg , -, , ! , , .

+1

. ( -), , , FTP - .

ASP AJAX, , @bang, , , .

AJAX , , . ( ), . ...

? ? , ? ?

. , Windows, , , .

If this seems a little shonkey, you can always write your long process with a little and have your aspx code-behind exchange data with this.

+1
source

Be aware of the IIS employee reinstall settings, as they can still affect your thread after it starts. Make sure you catch any exceptions and write them down.

0
source

All Articles