开发者

Which thread class except System.Threading in C# i can use in windows phone development? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be 开发者_StackOverflowreasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

Is there another c# class for threads, which works faster ?


Based on your comment, you are using the Thread class in the System.Threading namespace.

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:

  • The Thread class 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.
  • Using the ThreadPool class 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 the ThreadPool to schedule tasks, and your task will be placed in a queue; there's no way to force it to execute immediately when placed in the ThreadPool.
  • The Task and Task<TResult> classes in the System.Threading.Tasks namespace run on top of the ThreadPool (this can be configured otherwise, to run with new Thread instances 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.


For most circumstances using your own instances of the Thread class is going to be slower than using work items in the ThreadPool. It would take some extraordinary circumstances for you to find an advantage using the Thread class directly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜