Click here to Skip to main content
15,907,497 members
Home / Discussions / C#
   

C#

 
GeneralRe: I need a Sample code! Pin
Davood Riazi25-Nov-07 3:40
Davood Riazi25-Nov-07 3:40 
QuestionHow to count pixels Pin
A.Asif21-Nov-07 4:35
A.Asif21-Nov-07 4:35 
AnswerRe: How to count pixels Pin
V.21-Nov-07 4:47
professionalV.21-Nov-07 4:47 
AnswerRe: How to count pixels Pin
Skippums21-Nov-07 6:06
Skippums21-Nov-07 6:06 
QuestionHow to know if a thread is waiting for an event ?! Pin
Karma Komae21-Nov-07 4:14
Karma Komae21-Nov-07 4:14 
AnswerRe: How to know if a thread is waiting for an event ?! Pin
Luc Pattyn21-Nov-07 4:35
sitebuilderLuc Pattyn21-Nov-07 4:35 
GeneralRe: How to know if a thread is waiting for an event ?! Pin
Karma Komae21-Nov-07 4:52
Karma Komae21-Nov-07 4:52 
GeneralRe: How to know if a thread is waiting for an event ?! Pin
Luc Pattyn21-Nov-07 9:45
sitebuilderLuc Pattyn21-Nov-07 9:45 
In a process where there isn't much calculations going on (say a text editor) all
the threads are likely to be waiting for something to happen, such as a keyboard hit,
a mouse move, whatever.

In a process with lengthy calculations you will see threads that are not in WaitSleepJoin
state. Here is a simple test:

void Test() {
	List<Thread> threads=new List<Thread>();
	for(int i=0; i<4; i++) {
		Thread t=createThread("T"+i);
		threads.Add(t);
	}
	for(int i=0; i<100; i++) {
		Thread.Sleep(300);
		Console.WriteLine("tick "+i);
		foreach(Thread t in threads) {
			Console.WriteLine("Thread "+t.Name+": state = "+t.ThreadState);
		}
	}
}
 
Thread createThread(string name) {
	Thread t=new Thread(new ThreadStart(runner));
	t.IsBackground=true;
	t.Priority=ThreadPriority.BelowNormal;
	t.Name=name;
	t.Start();
	return t;
}
 
void runner() {
	for(int j=0; j<100; j++) {
		// use debug build (Release might throw out the following line)
		for(int i=0; i<100000000; i++) { }	// long loop
		Thread.Sleep(1000);
	}
}


Half of the time, some of the threads are in WaitSleepJoin (due to the Thread.Sleep in
runner), the other times they are really running.

Smile | :)

Luc Pattyn [Forum Guidelines] [My Articles]


this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets


GeneralRe: How to know if a thread is waiting for an event ?! Pin
Karma Komae21-Nov-07 23:05
Karma Komae21-Nov-07 23:05 
GeneralRe: How to know if a thread is waiting for an event ?! Pin
Luc Pattyn21-Nov-07 23:51
sitebuilderLuc Pattyn21-Nov-07 23:51 
QuestionHow to Open Url Pin
A.Asif21-Nov-07 3:54
A.Asif21-Nov-07 3:54 
AnswerRe: How to Open Url Pin
Skippums21-Nov-07 5:58
Skippums21-Nov-07 5:58 
QuestionReading data from ms sql Pin
RAGHAVENDRAN200721-Nov-07 3:06
RAGHAVENDRAN200721-Nov-07 3:06 
AnswerRe: Reading data from ms sql Pin
duncanmhor21-Nov-07 4:06
duncanmhor21-Nov-07 4:06 
QuestionForm.ShowDialog(), but without Focus Pin
blackjack215021-Nov-07 2:41
blackjack215021-Nov-07 2:41 
AnswerRe: Form.ShowDialog(), but without Focus Pin
Skippums21-Nov-07 5:27
Skippums21-Nov-07 5:27 
GeneralRe: Form.ShowDialog(), but without Focus Pin
blackjack215021-Nov-07 6:45
blackjack215021-Nov-07 6:45 
QuestionLoading an image into a toolStripStatusLabel Pin
Programm3r21-Nov-07 2:02
Programm3r21-Nov-07 2:02 
AnswerRe: Loading an image into a toolStripStatusLabel Pin
Andrei Ungureanu21-Nov-07 2:38
Andrei Ungureanu21-Nov-07 2:38 
GeneralRe: Loading an image into a toolStripStatusLabel Pin
Programm3r21-Nov-07 3:29
Programm3r21-Nov-07 3:29 
QuestionSend Messages to Mobile Devices Pin
Satish - Developer21-Nov-07 1:47
Satish - Developer21-Nov-07 1:47 
AnswerRe: Send Messages to Mobile Devices Pin
Vasudevan Deepak Kumar21-Nov-07 3:24
Vasudevan Deepak Kumar21-Nov-07 3:24 
Questiondrawing reverse rectangle using mouse Pin
_tasleem21-Nov-07 1:45
_tasleem21-Nov-07 1:45 
AnswerRe: drawing reverse rectangle using mouse Pin
Andrei Ungureanu21-Nov-07 2:28
Andrei Ungureanu21-Nov-07 2:28 
AnswerRe: drawing reverse rectangle using mouse [modified] Pin
Luc Pattyn21-Nov-07 4:43
sitebuilderLuc Pattyn21-Nov-07 4:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.