473,781 Members | 2,729 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Thread.Sleep...

Hi,

Currently I have a thread thats spinning and doing a
Thread.Sleep(so meTime).

I was thinking of changing this to Thread.Sleep(Ti meout.Infinite) ; then
when I have actual data in a collection to process in this thread, I was
going to do a _thread.Interru pt(); Would this be a better approach to
spinning a thread on ?
Jul 21 '05
26 2381
Normally for using collections one uses the provided .SynRoot property thats
there for that task. If you look at the examples for IEnumerable on
collecitons thats what it uses. collectionObj.S ynRoot

Still, I like to keep locks to a minimum and I dont see a need for a lock
there on an already synchronized object so AutoResetEvents seemed to me to
be more appropriate.

Being a win32 coder , AutoResetEvents makes more sense to me as you point
out.

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
news.microsoft. com <di********@dis cussion.microso ft.com> wrote:
I think most people are familiar with the concept of AutoResetEvents more than monitor pulse and wait so its even more readable.


That really depends on their background. If they're Java programmers
they'll be more familiar with monitors and waiting/notifying them. If
they're Win32 programmers they're probably more familiar with
AutoResetEvents .
Both achieve the
same effect as far as I can see except Monitor takes a lock on the object and autosetevent does not. Its just an event really. Since the item is
already synchronised I was more concerned about taking another lock on that object with Monitor.Wait/Pulse.


You don't have to use that particular object though - I usually
advocate using a separate object specifically for locking/waiting etc.
The cost of taking out a lock is pretty small, especially when
uncontested.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 21 '05 #21

To Alvin.

What's up with u dude - are you just a part-time ass or what? I
noticed ur stupid post towards someone who asked a question regarding
NGEN in one of the other .NET groups, as well as the rubbish ur
posting to Jon Skeet in this thread.

If you have something funny to say, then say it. If you have sod all
useful to say - look into a mirror and tell it to the only person who
cares.

I've seen other posts by you where you have actually helped a lot of
people, why do you then insist on posting crap at other times? There's
always one I guess.......
Jul 21 '05 #22
news.microsoft. com <di********@dis cussion.microso ft.com> wrote:
Normally for using collections one uses the provided .SynRoot property thats
there for that task. If you look at the examples for IEnumerable on
collecitons thats what it uses. collectionObj.S ynRoot
Yes, SyncRoot is fine for that purpose, but it's often nice to have
separate monitors specifically for thread waiting/notification. It just
makes life a bit easier to understand (IMO) and threading is a very
hard thing to get right to start with.
Still, I like to keep locks to a minimum and I dont see a need for a lock
there on an already synchronized object so AutoResetEvents seemed to me to
be more appropriate.

Being a win32 coder , AutoResetEvents makes more sense to me as you point
out.


You should be aware that AutoResetEvents almost certainly use their own
locks internally - I'd be very surprised if they were actually
significantly more efficient than using Monitor.Wait/Pulse. I'm not
saying you shouldn't use them - it's a matter of personal preference,
as I've said, and your last reason makes a lot of sense, but I wouldn't
focus too much on not having many locks. Making sure that you only lock
what you need to is more important, and that usually involves having
*more* locks available, to make each one finer-grained.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #23
NGEN? Can you post this so called thread so I can take a look at it.
NGEN in one of the other .NET groups, as well as the rubbish ur
posting to Jon Skeet in this thread.
What gives you the right to jump in here and declare it was rubbish? I have
solid reasons for posting a question like this. May be you should ask before
taking a shot eh?

My reason for posting this
Again I ask: why do you want to know?

it is just soooo discouraging, that's all.


was because I am feeling rather inadequate with my thread knowledge. I was
simply wanting to know if I needed to keep working in the pursuit of
increasing this knowledge or whether I should give it up and do something
else with my life. As he said, it took him a while to get there. I'm not
there yet. That is why it is discouraging to me. I wasn't going to reply to
your bullshit because I didn't think I was being a half ass. You could have
just asked instead of jumping the gun.

And by the way, an individual calling himself Jack Mayoff has been spoofing
my email account (and others by the way) replying to threads in my name. I
haven't caught all his attempts but you may be referring to one of his. I
wont give you the benefit of the doubt either. In short, if you follow my
post, it is rather easy to differentiate between me and a wanna be. But then
again, you couldn't get this last one so go figure.

shall we say an apology is in order? preach, do you think i was being a half
ass?
--
-----------
Got TidBits?
Get it here: www.networkip.net/tidbits
<Curious> wrote in message news:3f******** *******@news.mi crosoft.com...
To Alvin.

What's up with u dude - are you just a part-time ass or what? I
noticed ur stupid post towards someone who asked a question regarding
NGEN in one of the other .NET groups, as well as the rubbish ur
posting to Jon Skeet in this thread.

If you have something funny to say, then say it. If you have sod all
useful to say - look into a mirror and tell it to the only person who
cares.

I've seen other posts by you where you have actually helped a lot of
people, why do you then insist on posting crap at other times? There's
always one I guess.......

Jul 21 '05 #24

"Alvin Bruney" <vapordan_spam_ me_not@hotmail_ no_spamhotmail. com> wrote in
message news:el******** *****@TK2MSFTNG P12.phx.gbl...
NGEN? Can you post this so called thread so I can take a look at it.
NGEN in one of the other .NET groups, as well as the rubbish ur
posting to Jon Skeet in this thread.
What gives you the right to jump in here and declare it was rubbish? I

have solid reasons for posting a question like this. May be you should ask before taking a shot eh?
I have solid crap in my toilet.
My reason for posting this
Again I ask: why do you want to know?it is just soooo discouraging, that's all.


was because I am feeling rather inadequate with my thread knowledge. I was
simply wanting to know if I needed to keep working in the pursuit of
increasing this knowledge or whether I should give it up and do something
else with my life. As he said, it took him a while to get there. I'm not
there yet. That is why it is discouraging to me. I wasn't going to reply

to your bullshit because I didn't think I was being a half ass. You could have just asked instead of jumping the gun.

And by the way, an individual calling himself Jack Mayoff has been spoofing my email account (and others by the way) replying to threads in my name. I
haven't caught all his attempts but you may be referring to one of his. I
wont give you the benefit of the doubt either. In short, if you follow my
post, it is rather easy to differentiate between me and a wanna be. But then again, you couldn't get this last one so go figure.

shall we say an apology is in order? preach, do you think i was being a half ass?
--

No I don't think you were being a "half ass" I think you area a "complete
ass".

-----------
Got TidBits?
Get it here: www.networkip.net/tidbits
<Curious> wrote in message news:3f******** *******@news.mi crosoft.com...

To Alvin.

What's up with u dude - are you just a part-time ass or what? I
noticed ur stupid post towards someone who asked a question regarding
NGEN in one of the other .NET groups, as well as the rubbish ur
posting to Jon Skeet in this thread.

If you have something funny to say, then say it. If you have sod all
useful to say - look into a mirror and tell it to the only person who
cares.

I've seen other posts by you where you have actually helped a lot of
people, why do you then insist on posting crap at other times? There's
always one I guess.......


Jul 21 '05 #25

Yo.

Ahhh, well in that case it seems that indeed I was in the wrong. I
guess it was one of those days and I needed to get some steam out.

Having read some of your earlier posts and then reading "your" reply
to:

NGEN microsoft system dlls? by Bob Whiton in
microsoft.publi c.dotnet.perfor mance

I thought hang on, that's a bit out of order.

Again, appologies for jumping the gun there - never meant to upset you
in any way. I would feel bad if I did annoy you.

All the best dude.

'The mistakes of others are good teachers'. Proverb.
Jul 21 '05 #26
It's all good. No hard feelings.

--
-----------
Got TidBits?
Get it here: www.networkip.net/tidbits
<Curious> wrote in message news:3f******** ********@news.m icrosoft.com...

Yo.

Ahhh, well in that case it seems that indeed I was in the wrong. I
guess it was one of those days and I needed to get some steam out.

Having read some of your earlier posts and then reading "your" reply
to:

NGEN microsoft system dlls? by Bob Whiton in
microsoft.publi c.dotnet.perfor mance

I thought hang on, that's a bit out of order.

Again, appologies for jumping the gun there - never meant to upset you
in any way. I would feel bad if I did annoy you.

All the best dude.

'The mistakes of others are good teachers'. Proverb.

Jul 21 '05 #27

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

38
2908
by: Anthony Baxter | last post by:
On behalf of the Python development team and the Python community, I'm happy to announce the release of Python 2.3.1 (final). Python 2.3.1 is a pure bug fix release of Python 2.3, released in late July. A number of obscure crash-causing bugs have been fixed, various memory leaks have been squished, but no new features have been added to the language or to the library. For more information on Python 2.3.1, including download links for...
26
9613
by: news.microsoft.com | last post by:
Hi, Currently I have a thread thats spinning and doing a Thread.Sleep(someTime). I was thinking of changing this to Thread.Sleep(Timeout.Infinite); then when I have actual data in a collection to process in this thread, I was going to do a _thread.Interrupt(); Would this be a better approach to spinning a thread on ?
8
2785
by: Cider123 | last post by:
I ran into a situation where my Window Service had to process 100,000+ files, when I first noticed I needed to tweak various routines. Everything runs fine, but here's what I ran into: In the routine that loops through the file buffer: for (int i=0;i < _Buffer.length; i++) { // Code here
4
5434
by: Matthew Groch | last post by:
Hi all, I've got a server that handles a relatively high number of concurrent transactions (on the magnitude of 1000's per second). Client applications establish socket connections with the server. Data is sent and received over these connections using the asynchronous model. The server is currently in beta testing. Sporadically over the course of the day, I'll observe the thread count on the process (via perfmon) start climbing....
9
3488
by: Chris Dunaway | last post by:
According to the docs, calling Thread.Sleep(0) causes the thread to be "suspended to allow other waiting threads to execute." What happens if I call Thread.Sleep(500)? Do other threads not get a chance to execute during this time? What is the difference between the two? I have code that runs in a loop like this: Dim dResetTime As DateTime = DateTime.Now
6
2821
by: k.mellor | last post by:
Hi, I hope someone can help. I have written a simple form to demonstrate my problem/question. The code follows. The form starts a thread, which using delegates updates a label (Every second adds another dot to the label). This works great. However, when I put the GUI thread to sleep (Thread.Sleep), the thread seems to stall. At first I was expecting dots to still appear, but obviously as the GUI thread is asleep, they will not. ...
0
2696
by: Buckaroo Banzai | last post by:
Hello, newbie here... I'm writing this program but when I click the start button which should initiate either the Hare or the Tortoise, it does not, this is the first time I use threads, so the problem might be the way I'm passing the value. can someone please take a look at this code and maybe give me some guidance on what I'm doing wrong. Please note there are 3 separate files with the corresponding classes, I separated it with ===>...
9
6990
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
I've got a routine that builds a table using different queries, different SQL Tables, and adding custom fields. It takes a while to run (20 - 45 seconds) so I wrote a thread to handle the table population. Whenever I call the thread, I pass it a structure containing the table and a few other parameters. The table goes in as a reference, but the other items are passed normally.
2
3370
by: Steve | last post by:
Hi All, I've been trying to come up with a good way to run a certain process at a timed interval (say every 5 mins) using the SLEEP command and a semaphore flag. The basic thread loop was always sitting in the sleep command and not able to be interrupted. When the time came to set the semaphore flag to false (stopping the thread), my program would have to wait up to the entire sleep time to break out of the loop. I have finally found...
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10308
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9939
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8964
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7486
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6729
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5507
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4040
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2870
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.