Threading in ASP.NET (C#)

Discussion in 'ASP .Net' started by venkat, Jun 12, 2006.

  1. venkat

    venkat Guest

    Hi,
    I have a page that calls a sql procedure and it runs for 20 - 40 min. I
    use usual threading for this page.

    <code>Thread objthread = new Thread(new ThreadStart(ticketingThread));
    objthread.Start();</code>

    As i dont know when it will end. i never abort the thread. what happens
    is when user uses the page for 1 week, the page starts hanging. I dont
    know what happens. When i tried debugging it works fine.

    I also saw creating thread in threadpools

    <code>ThreadPool.QueueUserWorkItem(new
    WaitCallback(ticketingThread));</code>

    Please advise which one I have to follow and what is the difference
    between the two.

    Thanks
    Venkat
    venkat, Jun 12, 2006
    #1
    1. Advertising

  2. > I have a page that calls a sql procedure and it runs for 20 - 40 min.

    Should this really be run from a page? I would say that the page needs to
    register a "job" to do, and that a service application running on the server
    should process the jobs. The website can check back for the status of the
    job.


    --
    Pete
    ====
    Audio compression components, DIB graphics controls, ECO extensions,
    FastStrings
    http://www.droopyeyes.com

    My blog
    http://blogs.slcdug.org/petermorris/
    Peter Morris [Droopy eyes software], Jun 12, 2006
    #2
    1. Advertising

  3. venkat

    venkat Guest

    We proposed the same. but the clients want them in same web app

    Peter Morris [Droopy eyes software] wrote:
    > > I have a page that calls a sql procedure and it runs for 20 - 40 min.

    >
    > Should this really be run from a page? I would say that the page needs to
    > register a "job" to do, and that a service application running on the server
    > should process the jobs. The website can check back for the status of the
    > job.
    >
    >
    > --
    > Pete
    > ====
    > Audio compression components, DIB graphics controls, ECO extensions,
    > FastStrings
    > http://www.droopyeyes.com
    >
    > My blog
    > http://blogs.slcdug.org/petermorris/
    venkat, Jun 12, 2006
    #3
  4. venkat

    Damien Guest

    venkat wrote:
    > Peter Morris [Droopy eyes software] wrote:
    > > venkat wrote:
    > > > I have a page that calls a sql procedure and it runs for 20 - 40 min.

    > >
    > > Should this really be run from a page? I would say that the page needs to
    > > register a "job" to do, and that a service application running on the server
    > > should process the jobs. The website can check back for the status of the
    > > job.
    > >

    > We proposed the same. but the clients want them in same web app
    >

    Well, definitely create your own threads rather than using the thread
    pool - that's where ASP.Net draws it's threads from, so you'll be
    limiting it's normal service if you use the threadpool threads.

    As to the hanging, what's your memory usage like? Do you hook up any
    event handlers, or other delegates which might be causing your objects
    to lurk around in memory forever? Do you just throw away the thread
    reference or do you store it somewhere?

    The clients better have a *really* good reason for why they want this
    kind of thing happening within the one web app. Services are good at
    coming up when the server comes up, and staying up so long as the
    server is up. Web apps are really good (assuming you don't use InProc
    session) at being recycled whenever you need to, without affecting the
    end users (and at being scaled out if the website usage grows beyond a
    single server)

    Damien
    Damien, Jun 12, 2006
    #4
  5. if you use the trread pool, asp.net will know about it, and can catch
    errors, or abort the thread it runs too long. thedisadvantage is that you
    are tying up asp.net threads, you you could get a site too busy error. if
    you are not real experienced with threading, and monitoring threads, as you
    really shoudl use a queue and a pool for this application, then use the
    stardard pool.

    if you are using sql2005, I'd switch to broker services to run the sql
    request.

    -- bruce (sqlwork.com)


    "venkat" <> wrote in message
    news:...
    > Hi,
    > I have a page that calls a sql procedure and it runs for 20 - 40 min. I
    > use usual threading for this page.
    >
    > <code>Thread objthread = new Thread(new ThreadStart(ticketingThread));
    > objthread.Start();</code>
    >
    > As i dont know when it will end. i never abort the thread. what happens
    > is when user uses the page for 1 week, the page starts hanging. I dont
    > know what happens. When i tried debugging it works fine.
    >
    > I also saw creating thread in threadpools
    >
    > <code>ThreadPool.QueueUserWorkItem(new
    > WaitCallback(ticketingThread));</code>
    >
    > Please advise which one I have to follow and what is the difference
    > between the two.
    >
    > Thanks
    > Venkat
    >
    bruce barker \(sqlwork.com\), Jun 12, 2006
    #5
  6. > We proposed the same. but the clients want them in same web app

    If I want my car painted all I care about is how well it was done, I don't
    add clauses like "you must use a paint brush" :) Page requests should be
    served quickly and should *not* take long enough to have the word "minutes"
    in the time.

    The proper way to achieve this is to have the page register a job for a
    worker process to complete. I am curious as to why they believe they want
    it done this way. Surely you can convince them to change their minds within
    about 30 seconds once you explain the pro/con of each approach?

    Pete
    Peter Morris [Droopy eyes software], Jun 13, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lea Heart

    Why is threading a problem in ASP.Net ?

    Lea Heart, Aug 28, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    332
    Jerry III
    Aug 29, 2003
  2. Lea Heart
    Replies:
    1
    Views:
    420
    Steve C. Orr, MCSD
    Aug 28, 2003
  3. Replies:
    9
    Views:
    1,011
    Mark Space
    Dec 29, 2007
  4. Steven Woody
    Replies:
    0
    Views:
    394
    Steven Woody
    Jan 9, 2009
  5. Steven Woody
    Replies:
    0
    Views:
    434
    Steven Woody
    Jan 9, 2009
Loading...

Share This Page