Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions _rules/1825.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
---
rule_id: 1825
rule_category: performance
title: Prefer `Task.Run` or `Task.Factory.StartNew` for CPU-intensive activities
title: Prefer `Task.Run` for CPU-intensive activities
severity: 1
---
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.
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.

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.