Re: Safe multithreading in ASP.Net

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: John Saunders (johnwsaundersiii_at_notcoldmail.com)
Date: 08/06/04

  • Next message: John Saunders: "Re: Is there a way to obtain a Session object other than the current one ?"
    Date: Fri, 6 Aug 2004 04:33:45 -0400
    
    

    "who be dat?" <whatever@dot.com> wrote in message
    news:10h5vp3hujp9452@corp.supernews.com...
    > Consider the following code which enables multithreading in an ASP.Net
    > application I'm writing:

    ...

    > Suggestions?

    Yes. I suggest that you immediately cease all idea of using multithreading
    with ASP.NET! Pretend that threads just don't exist, or that any attempt to
    use threads with ASP.NET will cause horrible problems for you (which is
    true).

    Now, since nobody ever listens to such simple-minded suggestions, I'll try
    to explain. On every request, ASP.NET instantiates your Page object,
    processes it in several phases, then destroys it. Nothing that was on the
    page will remain after the request completes. This makes it very hard on any
    threads you've started during the request, if they do not terminate before
    the request terminates, as they will be operating on a dead page.

    The request will not wait for your threads. It doesn't have any idea that
    they exist. The fact that your threads still exist and are still referencing
    objects you created on the page will not save you - the objects may still
    exist, but their state may invalid. This especially goes for any objects
    created or manipulated by ASP.NET, since ASP.NET believes that the request
    is over, and so is unlikely to continue to maintain the state of any objects
    which belong to it.

    I strongly recommend that you learn some of the details of what ASP.NET is
    doing behind the scenes. Take a look at the following MSDN articles:

    The ASP.NET Page Object Model
    (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/htm
    l/aspnet-pageobjectmodel.asp?frame=true)

    Developing ASP.NET Server Controls
    (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/ht
    ml/cpconkeyconceptsinwebformscontroldevelopment.asp)

    -- 
    John Saunders
    johnwsaundersiii at hotmail
    

  • Next message: John Saunders: "Re: Is there a way to obtain a Session object other than the current one ?"

    Relevant Pages

    • Re: Safe multithreading in ASP.Net
      ... "John Saunders" wrote in ... On every request, ASP.NET ... > MSDN articles: ...
      (microsoft.public.dotnet.framework.aspnet)
    • Re: Albert Hofmanns letter to Steve Jobs
      ... I'm writing now, shortly after my 101st birthday, to request that you ... support Swiss psychiatrist Dr. Peter Gasser's proposed study of LSD- ... assisted psychotherapy in subjects with anxiety associated with life- ... Hopefully Dr. Gasser will be successful with his request. ...
      (rec.music.gdead)
    • Re: IIS Worker Process and File Access
      ... If an ASP.NET site is writing to a file, does the file get written as ... soon as the request is processed or once the IIS Worker Process queues ... Am I left to deal with a file access violation because ...
      (microsoft.public.dotnet.framework.aspnet)
    • HttpWebRequest and Multi Threaded apps Question
      ... Im in the process of writing a program that crawls a website. ... One problem Ive ran into is that when writing the response stream to the ... the process of making a Web Request time out. ...
      (microsoft.public.dotnet.framework)
    • HttpWebRequest and Multi Threaded Apps
      ... Im in the process of writing a program that crawls a website. ... One problem Ive ran into is that when writing the response stream to the ... the process of making a Web Request time out. ...
      (microsoft.public.dotnet.general)