-
Notifications
You must be signed in to change notification settings - Fork 6k
Description
The second example on this page shows a polling loop:
while(! task1.IsCompleted) {}
In this example it might not be too bad, but in general this kind of loop represents a massive inefficiency. Especially on a modern processor, it could cause a piece of code to execute billions of times more instructions than necessary.
I appreciate your code is only an example, but please don't ever show these polling loops in your examples. Somebody will copy the code, thinking it is safe because it was in an example on MSDN, and cause a lot of trouble, potentially for a lot of people, as a result.
If you have to put a polling loop in an example, please mark it with a big, loud warning that it should never be used in production code. Also, put a delay in the loop, even if it is very small.
Thanks,
Nick Roberts
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: 25bdb110-7ada-3817-bc40-9c11cab6513c
- Version Independent ID: 9476dc46-d4f0-e7f4-c21e-faaafe0433ea
- Content: Exception handling (Task Parallel Library)
- Content Source: docs/standard/parallel-programming/exception-handling-task-parallel-library.md
- Product: dotnet-fundamentals
- GitHub Login: @IEvangelist
- Microsoft Alias: dapine