Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8697349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:30:08+00:00 2026-06-13T01:30:08+00:00

I’m hoping to mold this post into a legitimate StackOverflow question, as I’d really

  • 0

I’m hoping to mold this post into a legitimate StackOverflow question, as I’d really like a solid understanding of this scenario, but I could definitely see if it’s too localized or considered an “opinion”.

Here’s my scenario: When I load my web app, I load a whole bunch of data from the database and cache it. The problem is, this process takes about 10-15 seconds and creates a lag when the web server first starts up. This is kinda annoying while developing, and also causes a few issues when I bounce the web server in production (since this is a new site, I’m often hot fixing small bugs as I find them, or mucking with IIS settings).

I got to wondering – Can I offload this work into a new thread when the application starts, and have this going on in the background as other users are using the site? Obviously, certain features wouldn’t work for about 10-15 seconds when the site loaded, but I can handle that condition or block until the data becomes available. At first, I was thinking no. The web server was going to either terminate these threads if the request ended, or block until these threads finished. I decided to write a little test app to test this theory:

public class Global : System.Web.HttpApplication
{
   void Application_Start(object sender, EventArgs e)
   {
      Thread thread = new Thread(LoadData);
      thread.Start();
   }

   private void LoadData()
   {
      for (int i = 0; i < 100; i++)
      {
         Trace.WriteLine("Counter: " + i.ToString());
         Thread.Sleep(1000);
      }
   }
}

When the app starts, I launch a new thread, and just have it count to 100. Much to my surprise, I immediately got to the home page and in my Visual Studio debug output window, I could see the incrementing numbers count up. I was actually surprised this works.

My Questions:

First off, are there any gotchas with doing this? Is it asking for trouble and is anything going to blow up? Will this behavior change between web servers, or versions of IIS as perhaps they use different threading models? I’m looking for overall feedback on this design.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T01:30:10+00:00Added an answer on June 13, 2026 at 1:30 am

    tl;dr: What you’re doing is probably fine, and a common way of dealing with this situation.

    There are certainly gotchas with threads. Not saying that you shouldn’t use them in this case, but you are wise to make sure you understand them. To abuse an old meme: “Programmers will often see a concurrency problem, and solve it by using another thread. Now they have two problems.”

    If your thread is meant to be a background thread (meaning that it shouldn’t prevent your site from shutting down if the thread is still running), make sure the IsBackground property is set. Better yet, use a BackgroundWorker.

    How usable is your site before the initialization thread has finished? Is there any real reason to show an interface while it is initializing?

    I’ve gone full-circle on directly using threads for concurrency – from being scared of them, to thinking I understood them and embracing them, to thinking I understand them and being scared of them. Right now, when I have a concurrency/async problem that I want to solve, I usually try to create an architecture composed of multiple, inter-communicating, concurrent (but single-threaded) processes. A lot of things get simpler that way, and I’ve had a lot of success with it.

    In your current case, using a background thread to handle the database load is probably safe enough if you can assure that you don’t access the resources that the thread is preparing before they are ready. However, (if you can target .Net 4.0), a better way to do what you want would be to leverage the Task Async library – which is to say, write your routines to be asynchronous, and return a Task of T instead of T itself. Done correctly, this can allow your site to be responsive to the user, even on an single-threaded environment, and even while it is still loading resources in the background.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
This could be a duplicate question, but I have no idea what search terms
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.