views:

82

answers:

1

I'm on IIS7

I have a button on a page.

When I click it, a new thread is started which calls a void method, which takes 20 to 30 minutes to complete.

The problem is the called void method stops running as soon as control is returned to the browser. (At least it appears to)

 protected void _Build_Click(object sender, EventArgs e)
        {
            if (Build.IsBuilding) return;
            var t = new Thread(Build.DoBuild);
            t.Start();
        }

Should it behave this way or should control be returned to the browser and continue? Is there another way to invoke a method and not wait for it to complete?

+1  A: 

I suppose your method being stopped by script timeout. There are different ways to fix it:

  1. Increase script timeout. I would not recommend this one, as the long operation locks Application pool thread and it can't process other requests. But you can try :) http://www.devx.com/vb2themax/Tip/18803
  2. Using asynchronous methods. http://msdn.microsoft.com/en-us/magazine/cc163725.aspx
  3. Workflows http://msdn.microsoft.com/en-us/magazine/2009.01.longrunwf.aspx
  4. Execute your process with Ajax request to the web service and polling the service to check the execution status.
Artem K.