473,503 Members | 1,136 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Thread.yeild

Is there something in C# that is similar to Java's Thread.yield?
Currently I am using the 1.1 framework.

Oct 12 '07 #1
5 3626
On Oct 12, 2:13 pm, Benjamin The Donkey <spacemonke...@gmail.com>
wrote:
Is there something in C# that is similar to Java's Thread.yield?
Currently I am using the 1.1 framework.
It's been a while since I've worked with Java, but if I remember
correctly, it is giving up the current threads timeslice... If that's
the case:

Thread.Sleep(0) should do the trick.

--
Tom Shelton

Oct 12 '07 #2
Tom Shelton wrote:
>Is there something in C# that is similar to Java's Thread.yield?
Currently I am using the 1.1 framework.

It's been a while since I've worked with Java, but if I remember
correctly, it is giving up the current threads timeslice... If that's
the case:

Thread.Sleep(0) should do the trick.
You will want to call with a parameter of 1 instead of 0 if you want to
guarantee that the call will yield to some other thread (in particular,
a lower-priority thread).

Calling with 0 for the parameter will only allow another thread to run
if that thread is of equal or higher priority to the thread making the
call. If there's no such thread, the thread making the call will
continue to run, even if there are lower-priority threads ready and
waiting to run.

If that's not a concern, Thread.Sleep(0) should work fine.

Pete
Oct 12 '07 #3
On Oct 12, 5:26 pm, Peter Duniho <NpOeStPe...@NnOwSlPiAnMk.comwrote:
Tom Shelton wrote:
Is there something in C# that is similar to Java's Thread.yield?
Currently I am using the 1.1 framework.
It's been a while since I've worked with Java, but if I remember
correctly, it is giving up the current threads timeslice... If that's
the case:
Thread.Sleep(0) should do the trick.

You will want to call with a parameter of 1 instead of 0 if you want to
guarantee that the call will yield to some other thread (in particular,
a lower-priority thread).

Calling with 0 for the parameter will only allow another thread to run
if that thread is of equal or higher priority to the thread making the
call. If there's no such thread, the thread making the call will
continue to run, even if there are lower-priority threads ready and
waiting to run.

If that's not a concern, Thread.Sleep(0) should work fine.

Pete
You know, I just recently read that... You learn something new
everyday.

--
Tom Shelton

Oct 13 '07 #4
On Oct 12, 7:26 pm, Peter Duniho <NpOeStPe...@NnOwSlPiAnMk.comwrote:
Tom Shelton wrote:
Is there something in C# that is similar to Java's Thread.yield?
Currently I am using the 1.1 framework.
It's been a while since I've worked with Java, but if I remember
correctly, it is giving up the current threads timeslice... If that's
the case:
Thread.Sleep(0) should do the trick.

You will want to call with a parameter of 1 instead of 0 if you want to
guarantee that the call will yield to some other thread (in particular,
a lower-priority thread).

Calling with 0 for the parameter will only allow another thread to run
if that thread is of equal or higher priority to the thread making the
call. If there's no such thread, the thread making the call will
continue to run, even if there are lower-priority threads ready and
waiting to run.

If that's not a concern, Thread.Sleep(0) should work fine.

Pete
hmm... i am not sure if it makes sense to yeild to a thread with lower
priority anyway?

Oct 17 '07 #5
Benjamin The Donkey wrote:
hmm... i am not sure if it makes sense to yeild to a thread with lower
priority anyway?
It would depend on why you're yielding in the first place. But yes,
there are situations in which you would want to call Sleep(0) instead of
Sleep(1). It just depends on what behavior you want.

My point in replying was to make sure it's understood that Sleep(0) does
not guarantee that your thread will actually yield to some other thread.
If that's okay, or even desirable, then Sleep(0) is indeed what you'd
want to do.

Pete
Oct 17 '07 #6

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

Similar topics

14
2152
by: adeger | last post by:
Having trouble with my first forays into threads. Basically, the threads don't seem to be working in parallel (or you might say are blocking). I've boiled my problems to the following short code...
4
2874
by: Gilles Leblanc | last post by:
Hi I have started a small project with PyOpenGL. I am wondering what are the options for a GUI. So far I checked PyUI but it has some problems with 3d rendering outside the Windows platform. I...
7
2685
by: Ivan | last post by:
Hi I have following problem: I'm creating two threads who are performing some tasks. When one thread finished I would like to restart her again (e.g. new job). Following example demonstrates...
4
5415
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...
5
2814
by: Razzie | last post by:
Hi all, A question from someone on a website got me thinking about this, and I wondered if anyone could explain this. A System.Threading.Timer object is garbage collected if it has no...
16
3286
by: droopytoon | last post by:
Hi, I start a new thread (previous one was "thread timing") because I have isolated my problem. It has nothing to do with calling unmanaged C++ code (I removed it in a test application). I...
9
3050
by: mareal | last post by:
I have noticed how the thread I created just stops running. I have added several exceptions to the thread System.Threading.SynchronizationLockException System.Threading.ThreadAbortException...
13
5054
by: Bob Day | last post by:
Using vs2003, vb.net I start a thread, giving it a name before start. Code snippet: 'give each thread a unique name (for later identification) Trunk_Thread.Name = "Trunk_0_Thread" ' allow...
7
2671
by: Charles Law | last post by:
My first thought was to call WorkerThread.Suspend but the help cautions against this (for good reason) because the caller has no control over where the thread actually stops, and it might have...
0
7203
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7282
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,...
0
7339
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6995
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5581
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,...
0
4678
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...
0
3168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3157
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
389
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...

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.