Skip to content

Don't put polling loops into examples! #29010

@theREALdebater

Description

@theREALdebater

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions