Threading in C#

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • venkat

    Threading in C#

    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(tic ketingThread));
    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>ThreadPoo l.QueueUserWork Item(new
    WaitCallback(ti cketingThread)) ;</code>

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

    Thanks
    Venkat

  • Tasos Vogiatzoglou

    #2
    Re: Threading in C#

    It would be pretty difficult to provide any kind of help for this
    problem, as there is no source-code or a more specific indication about
    the threading code, application, database.

    It could be from a threading race condition to a database lock to
    resources exhaustion.

    Now, for your second question, by using ThreadPool you pick a thread
    from the ThreadPool (whenever and if it's available) and you ensure
    that the thread will be returned to the pool and you won't have an
    arbitary number of thread running.

    What you will follow is a matter of requirements.

    Regards,
    Tasos

    venkat wrote:[color=blue]
    > 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(tic ketingThread));
    > 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>ThreadPoo l.QueueUserWork Item(new
    > WaitCallback(ti cketingThread)) ;</code>
    >
    > Please advise which one I have to follow and what is the difference
    > between the two.
    >
    > Thanks
    > Venkat[/color]

    Comment

    • venkat

      #3
      Re: Threading in C#

      Thanks Tasos,
      The scenario is I have a button that initiate the ticket processing.
      (You can call it like a batch process). It calls a procedure and it
      internally calls number of procedures. If the number of items to be
      processed is less, then it will take 10-25 min, and max is 40 min. This
      is a maintenence work. The existing code works very well but. on due
      course the particular page starts hanging. there is no spl code in
      that. It has two drop down with two items in it. on slections of those
      items user has to click initiate process button. If I restart www
      service it starts working fine. that is why I came in to conslusion the
      problem is with the threads. (is this correct).

      Thanks
      Venkat

      Tasos Vogiatzoglou wrote:[color=blue]
      > It would be pretty difficult to provide any kind of help for this
      > problem, as there is no source-code or a more specific indication about
      > the threading code, application, database.
      >
      > It could be from a threading race condition to a database lock to
      > resources exhaustion.
      >
      > Now, for your second question, by using ThreadPool you pick a thread
      > from the ThreadPool (whenever and if it's available) and you ensure
      > that the thread will be returned to the pool and you won't have an
      > arbitary number of thread running.
      >
      > What you will follow is a matter of requirements.
      >
      > Regards,
      > Tasos
      >
      > venkat wrote:[color=green]
      > > 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(tic ketingThread));
      > > 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>ThreadPoo l.QueueUserWork Item(new
      > > WaitCallback(ti cketingThread)) ;</code>
      > >
      > > Please advise which one I have to follow and what is the difference
      > > between the two.
      > >
      > > Thanks
      > > Venkat[/color][/color]

      Comment

      • chanmm

        #4
        Re: Threading in C#

        Is it necessary for you to use threading in webform?

        chanmm

        "venkat" <venkatsriram@g mail.com> wrote in message
        news:1150114517 .890558.215430@ u72g2000cwu.goo glegroups.com.. .[color=blue]
        > Thanks Tasos,
        > The scenario is I have a button that initiate the ticket processing.
        > (You can call it like a batch process). It calls a procedure and it
        > internally calls number of procedures. If the number of items to be
        > processed is less, then it will take 10-25 min, and max is 40 min. This
        > is a maintenence work. The existing code works very well but. on due
        > course the particular page starts hanging. there is no spl code in
        > that. It has two drop down with two items in it. on slections of those
        > items user has to click initiate process button. If I restart www
        > service it starts working fine. that is why I came in to conslusion the
        > problem is with the threads. (is this correct).
        >
        > Thanks
        > Venkat
        >
        > Tasos Vogiatzoglou wrote:[color=green]
        >> It would be pretty difficult to provide any kind of help for this
        >> problem, as there is no source-code or a more specific indication about
        >> the threading code, application, database.
        >>
        >> It could be from a threading race condition to a database lock to
        >> resources exhaustion.
        >>
        >> Now, for your second question, by using ThreadPool you pick a thread
        >> from the ThreadPool (whenever and if it's available) and you ensure
        >> that the thread will be returned to the pool and you won't have an
        >> arbitary number of thread running.
        >>
        >> What you will follow is a matter of requirements.
        >>
        >> Regards,
        >> Tasos
        >>
        >> venkat wrote:[color=darkred]
        >> > 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(tic ketingThread));
        >> > 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>ThreadPoo l.QueueUserWork Item(new
        >> > WaitCallback(ti cketingThread)) ;</code>
        >> >
        >> > Please advise which one I have to follow and what is the difference
        >> > between the two.
        >> >
        >> > Thanks
        >> > Venkat[/color][/color]
        >[/color]


        Comment

        • Brian Gideon

          #5
          Re: Threading in C#

          Venkat,

          You said this was maintenance work. Why not just run the stored
          procedure as a scheduled job? Why are you calling it from a web page
          anyway?

          Brian

          venkat wrote:[color=blue]
          > Thanks Tasos,
          > The scenario is I have a button that initiate the ticket processing.
          > (You can call it like a batch process). It calls a procedure and it
          > internally calls number of procedures. If the number of items to be
          > processed is less, then it will take 10-25 min, and max is 40 min. This
          > is a maintenence work. The existing code works very well but. on due
          > course the particular page starts hanging. there is no spl code in
          > that. It has two drop down with two items in it. on slections of those
          > items user has to click initiate process button. If I restart www
          > service it starts working fine. that is why I came in to conslusion the
          > problem is with the threads. (is this correct).
          >
          > Thanks
          > Venkat
          >[/color]

          Comment

          • Ignacio Machin \( .NET/ C# MVP \)

            #6
            Re: Threading in C#

            Hi,

            "Brian Gideon" <briangideon@ya hoo.com> wrote in message
            news:1150120982 .288774.282950@ h76g2000cwa.goo glegroups.com.. .[color=blue]
            > Venkat,
            >
            > You said this was maintenance work. Why not just run the stored
            > procedure as a scheduled job? Why are you calling it from a web page
            > anyway?[/color]

            Probably cause the parameters change, It's ok to call it from a webpage,
            it's not waiting for the result to show in the webpage though.


            --
            --
            Ignacio Machin,
            ignacio.machin AT dot.state.fl.us
            Florida Department Of Transportation


            Comment

            • Ken

              #7
              Re: Threading in C#

              Brian Gideon wrote:[color=blue]
              > Venkat,
              >
              > You said this was maintenance work. Why not just run the stored
              > procedure as a scheduled job? Why are you calling it from a web page
              > anyway?
              >
              > Brian
              >[/color]
              Venkat,

              We have a number of processes that take some time to execute. There is
              just no way for us to run these things from the web server. If
              possible, it is best to run them on a separate processing computer.

              We use several queue tables, where the user (or another process)
              inserts a request to do something. The process, running on a separate
              computer sees this request in the queue, does it's processing and
              e-mails the requestor that the process is done.

              We tried threads on the webserver but there were many problems. It
              just didn't work well. Plus, by placing the heavy-duty processing on
              seperate PCs, the web server can do what it does best... Serve web
              pages.

              Ken - KC7RAD
              ANI NETWORKS Smarter Connections. Trusted Solutions. For nearly 40 years, carrier and enterprise customers have trusted ANI Networks to deliver reliable toll-free, data, and termination services — backed by nationwide coverage, real-time routing intelligence, and world-class support. Explore Services Contact Sales Our Services at a Glance ANI Networks makes call delivery smarter, faster, and more […]


              Comment

              Working...