In unmanaged code you can create a thread in suspended state. In .NET Framework I can’t find this option. Is it because the Thread constructor puts the thread in a suspended state? Is there other reason why this is not supported?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
When you create a new
Thread, itsThreadStateisThreadState.Unstarted, notThreadState.Suspended.This may correspond to a suspended thread at the OS level; however, the implementation details of a managed thread are something you should not be concerning yourself with. .NET threads are more than just simple wrappers around unmanaged threads.
You may also note that the
SuspendandResumemethods of theThreadclass are marked as obsolete, with this scary warning:Directly suspending and resuming threads is highly discouraged in .NET, and if you started a thread “as suspended”, then you would have to
Resumeit. They want to discourage people from using any of these methods, so instead they use the specialUnstartedstatus and get you toStartthe thread instead ofResumingit. It’s a much cleaner abstraction anyway.Summary: The option is not directly available to you because you are not supposed to be suspending or resuming threads at all – leave that up to the .NET runtime, or even better, use the
ThreadPoolwhen you can.