Multithreading

ASP.NET C#

Multithreading


chris 03-24-2007, 4:36 PM
    I'm trying to do some very simple multithreading on my ASP.NET 2.0 application hosted on the Advanced package on WebHost4Life. I'm using the ThreadPool like so:

            bool result = ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadProc), tt);

It works great in my local test environment but on the WH4L server it doesn't execute. The result is set to true on the return to that call back ThreadProc is never invoked. At the moment I'm not trying to do anything fancy - just writing to a log file to observe the multithreading in action and make sure that it works - or in this case doesn't work.

Anyway, has anybody used multithreading in their ASP.NET application? Does it work on WH4L servers?

I'm wondering if it's been disabled on the WH4L servers? Can you disable that sort of thing?

Re: Multithreading


chris 03-25-2007, 4:22 PM
I have asked this same question with more details and a code sample (if anybody wants to see what the results are and the code used) on the asp.net forum:

http://forums.asp.net/thread/1636213.aspx

Re: Multithreading


Milo 06-10-2008, 12:45 AM
Have you just tried with one thread, then try two...? To make sure this IS a threading restriction.

You can restrict IIS through the Application pooling to max CPU usage (% and refresh)

Not sure how WH4L set the websites up, but I would have setup one pool, per website account and .net versions

Re: Multithreading


savant 07-26-2008, 5:45 AM
There are settings for the .NET ThreadPool that can be set by WH4L at the server or application level, but the only way to find out reliably is by running some code inside your environment. Create an ASP.NET page, add an asp:Literal control to it with an ID of 'Results' (also remember to set 'runat=server' too), then include the following in the Page_Load event in the code-behind file:

      int workerThreads;
      int completionPortThreads;
      int maxWorkerThreads;
      int maxCompletionPortThreads;
      int minWorkerThreads;
      int minCompletionPortThreads;

      ThreadPool.GetAvailableThreads(out workerThreads, out completionPortThreads);
      ThreadPool.GetMaxThreads(out maxWorkerThreads, out maxCompletionPortThreads);
      ThreadPool.GetMinThreads(out minWorkerThreads, out minCompletionPortThreads);

      Results.Text = "Available Threads: " + workerThreads.ToString() + " / " +
          completionPortThreads.ToString() +
          "<br>Max Threads: " + maxWorkerThreads.ToString() + " / " +
          maxCompletionPortThreads.ToString() +
          "<br>Min Threads: " + minWorkerThreads.ToString() + " / " +
          minCompletionPortThreads.ToString();


What this does is interrogate the ThreadPool itself to discover its settings. What I got when I ran it was 100 worker threads maximum with 99 available (obviously because the page itself is taking up one of those threads to do its own work).

If you are getting similar results, then the issue is most probably with your code.
 
webhost4life.com

Powered by Community Server, by Telligent Systems