Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have created thread as
C#
Thread th = new Thread(DoSomething);
    th.IsBackground = true;

but th.sleep(); not working
but at the same time main thread
C#
System.Threading.Thread.Sleep(1000);

working fine
Please suggest
Posted
Updated 26-Nov-11 21:33pm
v3
Comments
[no name] 27-Nov-11 0:49am    
I suugest you properly format you question, use pre tags around code, not use txt speak and not shout, don't use all caps

1 solution

"Not working" means: it won't compile. That's correct.

The method System.Threading.Thread.Sleep is static. You don't need a thread reference to indicate what thread should be effected: the thread to be put to sleep is the current thread. In this way, a code thread can put to sleep only the same thread running this code. This is a common paradigm of all threaded systems.

—SA
 
Share this answer
 
Comments
Mehdi Gholam 27-Nov-11 2:09am    
5'ed
Sergey Alexandrovich Kryukov 27-Nov-11 11:56am    
Thank you, Mehdi.
--SA
[no name] 27-Nov-11 4:12am    
agree
Sergey Alexandrovich Kryukov 30-Nov-11 20:20pm    
Good. Thank you, Eduard.
--SA
Rakesh S S 27-Nov-11 9:37am    
TRUE

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900