views:

146

answers:

1

Hi everyone,

I have an ASP.NET MVC application, and in one of the controllers I have two long-running operations. I want to execute them in parallel.

At first, I simply rolled my own multithreading code by new'ing up a System.Threading.Thread() object, running it in the background, and thread.Join()ing it up before exiting the controller. Worked fine.

A co-worker pointed me at the System.Web.UI.PageAsyncTask class. It seems straightforward enough and event-driven, but it seems like it will work too.

Any compelling reason to choose PageAsyncTask over a simple Thread?

Thanks!

-Mike

+1  A: 

PageAsyncTask should not be used in an MVC application. MVC 2 has an AsyncController class that can be used for this purpose instead. But if your operations are very simple and manual threading is working out for you, you're probably fine sticking with your current implementation.

Levi
can you elaborate a little more please? why shouldn't a PageAsyncTask be used in MVC?
Mike
The PageAsyncTask type is intimately tied to the Page class (specifically, the Page.RegisterAsyncTask() method). This code path that kicks these tasks isn't guaranteed to get called correctly during the lifecycle of an MVC request. Essentially, pages should be used strictly as dumb templating systems for MVC views.
Levi