You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
title: Prefer `Task.Run` or `Task.Factory.StartNew` for CPU-intensive activities
4
+
title: Prefer `Task.Run` for CPU-intensive activities
5
5
severity: 1
6
6
---
7
-
If you do need to execute a CPU bound operation, use `Task.Run` to offload the work to a thread from the Thread Pool. For long-running operations use `Task.Factory.StartNew` with `TaskCreationOptions.LongRunning` parameter to create a new thread. Remember that you have to marshal the result back to your main thread manually.
7
+
If you need to execute a CPU-bound operation, use `Task.Run` to offload the work to a thread from the Thread Pool. Remember that you have to marshal the result back to your main thread manually.
8
+
9
+
For long-running operations, use `Task.Factory.StartNew` with `TaskCreationOptions.LongRunning` to hint the runtime to use a dedicated thread instead of a thread pool thread.
0 commit comments