Fiona

Fiona

  • NA
  • 8
  • 0

Thread.Start not running anything?

Jun 12 2006 10:43 AM
Hi,

I'm new to threading and would appreciate a little help. Have looked around for answers to my problem, but can't find anything, even thought I'm sure it's easy!

I have a process in my ASP.NET app which takes a long time to complete (basically it creates a monster PDF file). What I would like to happen is for user to be able to click the button to create this file and then continue with their site experience while the file is generated in the background.

I thought threading might be the solution to this, so have come up with the following:

public void archiveSite()
{
ThreadStart threadFunc = new ThreadStart (threadedArchiveSite);
Thread fThread =
new Thread (threadFunc);
fThread.Start ();

HttpContext.Current.Response.Write(fThread.IsAlive.ToString());  // this dumps "True"

}

public void threadedArchiveSite()
{
//do all the gubbins to create my PDF
}

Now, as much as calling archiveSite() now doesn't make the browser sit there like a lemon for five minutes, unfortunately the PDF isn't created.
There's no error in the code, because if I put a direct call to threadedArchiveSite() inside archiveSite() it works fine.

I know I muct be missing something here.

Any hints?

Thanks :D