views:

103

answers:

3

Hi folks,

I have an ASP.NET application that starts a long running operation during the Event Handler phase in the ASP.NET Page life cycle. This occurs when the end user pushes a button a bunch of queries are made to a database, a bunch of maps are generated, and then a movie is made from jpeg images of the maps. This process can take over a minute to complete.

Here's a link to the application http://maxim.ucsd.edu/mapmaker/cbeo.aspx

I've tried using a thread from the threadpool, creating and launching my own thread and using AsyncCallback framework. The problem is that the new thread is run under a different userid. I assume the main thread is run under ASPNET, the new thread is run under AD\MAXIM$ where MAXIM is the hostname. I know this because there is an error when it tries to connect to the database.

Why is the new thread under a different userid? If I can figure out the userid issue, what I'd like to do is check if the movie making process has finished by examining a Session variable in a Page_Load method, then add a link to the page to access the movie.

Does anyone have any good examples of using concurrency in a ASP.NET application that uses or creates threads in an EventHandler callback?

Thanks, Matt

+2  A: 

Did you read this?: http://msdn.microsoft.com/en-us/magazine/cc163725.aspx

Quoting one relevant portion from that link (you should read the whole thing):

A final point to keep in mind as you build asynchronous pages is that you should not launch asynchronous operations that borrow from the same thread pool that ASP.NET uses.

zvolkov
A: 

Not addressing the specific problem you asked about, but this is likely to come up soon:

At what point is this video used?

  • If it's displayed in the page or downloaded by the user, what does the generated html that the browser uses to get the video look like? The browser has to call that video somewhere using a separate http request, and you might do better by creating a separate http handler (*.ashx file) to handle that request, and just writing the url for that handler in your page.
  • If it's for storage or view elsewhere you should consider just saving the information needed to create the video at this point and deferring the actual work until the video is finally requested.
Joel Coehoorn
A: 

The problem is that the new thread is run under a different userid. I assume the main thread is run under ASPNET, the new thread is run under AD\MAXIM$ where MAXIM is the hostname.

ASPNET is a local account, when the request travels over a network it will use the computer's credentials (AD\MAXIM$).

What may be happening, is that you're running under impersonation in the request - and without in the ThreadPool. If that's the case, you might be able to store the current WindowsIdentity for the request, and then impersonate that identity in the ThreadPool.

Or, just let the ThreadPool hit the DB with Sql Authentication (username and password).

Mark Brackett