Newbie threading question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • xtech1005
    New Member
    • Jul 2008
    • 9

    Newbie threading question

    hello,

    I have a c# windows service that is working fine but I don't fully understand how the threading works. A new MTAThread is created and started. The method it is assigned to runs a couple of queries and at the end it calls Thread.Sleep (10000). At the end of this wait period the process repeats.

    But, I don't understand what makes it go back to the beginning of the method and start over. There isn't any reset or any other call to make this happen.

    Here is a snippet of the method:
    Code:
    private void updateTags()
    {
    //DB work done here...
    Thread.Sleep(10000)
    }
    What could make this routine repeat itself?

    thanks,
    steve
    Last edited by tlhintoq; Jan 27 '10, 11:36 PM. Reason: [CODE] ...Your code goes between code tags [/CODE]
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.

    Comment

    • tlhintoq
      Recognized Expert Specialist
      • Mar 2008
      • 3532

      #3
      Nothing is a thread.sleep call will cause a repeat.
      Beyond that, there is nothing else in your post to go on.

      I would guess that an event is mapped to the method, so every time 'x' happens the method is called.

      Or a loop exists elsewhere that is calling this method repeatedly.

      Comment

      • xtech1005
        New Member
        • Jul 2008
        • 9

        #4
        Thanks tlhintoq,

        That was my main concern was whether something in the thread itself would cause it to repeat. I'll go back and look again through the rest of the code.

        Also, thanks for the tip about using tags. I'll use them in future posts.

        Thanks!

        Comment

        • xtech1005
          New Member
          • Jul 2008
          • 9

          #5
          Thanks for the additional information.

          I found what causes the looping after Thread.Sleep and I'm embarrased to say.

          The routine is acutally wrapped in a while loop but it wasn't obvious when I first looked over the code. It is a code sample for an activeX that I bought to build an opc server. Since I'm not real familiar with threading I first thought it had something to do with that.

          Thanks for everyone's input. cheers!

          Comment

          • tlhintoq
            Recognized Expert Specialist
            • Mar 2008
            • 3532

            #6
            Sanjib65: In the future please do not hijack someone else's thread/question for your own needs. You are always welcome to start a new thread and even reference an existing thread.

            "I was looking at this question xxxxxxxx when it got me thinking about zzzzzzz"

            I have split your question and PRR's answers to their own thread.

            Comment

            Working...