-
Notifications
You must be signed in to change notification settings - Fork 147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Analyzer proposal: Use Task.Delay instead of Thread.Sleep in an async method #754
Comments
|
Makes sense. Does reaching out mean cross-posting to a different repo, or something else? |
Yes. But I can't remember which dotnet repo keeps the new analyzers. |
They are filling them directly in the runtime repository, here's an example: dotnet/runtime#67123. //cc @terrajobst |
Task. Sleep is a synchronous thread that puts the thread to sleep so it can't be used for anything else. Task, on the other hand. Delay is an asynchronous thread that can be used to perform other tasks while it waits. Refer to this https://kodlogs.net/1/task-delay-vs-thread-sleep |
@snjjay: I think instead of "Task. Sleep" you meant "Thread.Sleep". It's not clear to me what point you were trying to make with your comment. I think everyone here understands the difference between the two methods. |
Using
Thread.Sleep()
inside anasync
method is a bad idea.await Task.Delay()
is a drop-in replacement. It would be great to have an analyzer rule (and an accompanying code fix) to catch accidental use ofThread.Sleep
.Back on the old AsyncUsageAnalyzers repo, there was this discussion: DotNetAnalyzers/AsyncUsageAnalyzers#2
And also a related PR: DotNetAnalyzers/AsyncUsageAnalyzers#50
Is vs-threading the right place for an analyzer like this?
The text was updated successfully, but these errors were encountered: