Is there another c# class for threads, which works faster ?
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.
Based on your comment, you are using the
Threadclass in theSystem.Threadingnamespace.Based on that, none of the classes are going to make the code that executes on the thread any faster; the best you can do is optimize the performance of the mechanism that you use for your situation.
That said, there are some things to be aware of:
Threadclass probably has the most overhead; every time you create one, it creates a new managed thread, which might create a new OS thread. This is not an inconsequential operation.ThreadPoolclass to schedule operations can be faster in terms of starting your operation, as it keeps a cache of threads already created so you don’t have to pay that penalty. The trade-off here is that a) many classes in the .NET framework use theThreadPoolto schedule tasks, and your task will be placed in a queue; there’s no way to force it to execute immediately when placed in theThreadPool.TaskandTask<TResult>classes in theSystem.Threading.Tasksnamespace run on top of theThreadPool(this can be configured otherwise, to run with newThreadinstances every time, for example), so you gain those benefits, but at the same time, there is overhead for cancellation, continuation, etc, etc. You gain ease-of-use here (much in my opinion), with minimal overhead.In the end, you will have to measure what is best for your application and apply that solution; like most, there is no one-size-fits-all solution.