468,512 Members | 1,544 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,512 developers. It's quick & easy.

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:
Expand|Select|Wrap|Line Numbers
  1. private void updateTags()
  2. {
  3. //DB work done here...
  4. Thread.Sleep(10000)
  5. }
What could make this routine repeat itself?

thanks,
steve
Jan 27 '10 #1

✓ answered by tlhintoq

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.

5 984
tlhintoq
3,525 Expert 2GB
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.
Jan 27 '10 #2
tlhintoq
3,525 Expert 2GB
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.
Jan 27 '10 #3
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!
Jan 27 '10 #4
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!
Jan 28 '10 #5
tlhintoq
3,525 Expert 2GB
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.
Jan 28 '10 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

65 posts views Thread by Anthony_Barker | last post: by
4 posts views Thread by Antal Rutz | last post: by
6 posts views Thread by CK | last post: by
7 posts views Thread by Anthony Nystrom | last post: by
4 posts views Thread by Bob | last post: by
4 posts views Thread by DBC User | last post: by
19 posts views Thread by frankiespark | last post: by
10 posts views Thread by sd | last post: by
3 posts views Thread by Sparky | last post: by
2 posts views Thread by James Calivar | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.