Question About Application_Start in Global.asax and async functions

  • Thread starter Thread starter Bob Johnson
  • Start date Start date
B

Bob Johnson

Hello people.

Short background -- I am constructing a web site that will have several
display tabs that are hooked up to different datatables in a SQL server.
Some of these tables are VERY large -- several million+ records. The tables
have records that are timestamped over several years and
months/quarter/weeks... depending on the individual table they can have
anywhere between 30 and 300 geography/time combinations.

What I would like to do in Application_Start is to create several metadata
objects (datasets) that control what the drop down choices are for the user
to select on each of the main data pages. The problem is sometimes filling
these datatables takes 30-40 seconds+.

So: how do I create something in application_start that fires off a
function that creates and populates my application level objects in a "fire
& forget " method. I can do threading and async calls all day long in win32
forms programming -- this is the first time though I've needed it in ASP.net

Thnx

Bob J
 
Here are some resources on Threading in ASP.NET using System.Threading

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemthreading.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconthreadpooling.asp

Here's a quick example. In this example, I'm writing to my db, and at the
same time, wanna email the user. So here's what I do:

In my button click event
{
ForkThreadSendInviteEmails();
Response.Redirect("default.aspx", true);
}

private void ForkThreadSendInviteEmails()
{
Thread thEmailInvoice = new Thread(new ThreadStart(SendInviteEmails));
thEmailInvoice.Priority = ThreadPriority.AboveNormal;
thEmailInvoice.Start();
}
 
sorry, I hit Sendtoo soon.

In my ForkThreadSendInviteEmails function, you see the line:
Thread thEmailInvoice = new Thread(new ThreadStart(SendInviteEmails));

You would also have to implement the SendInviteEmails function.
 
Back
Top