dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.08k stars 4.7k forks source link

Deprecate BackgroundWorker.RunWorkerAsync #25381

Open GerjanOnline opened 6 years ago

GerjanOnline commented 6 years ago

For me, it is very misleading that BackgroundWorker.RunWorkerAsync uses the convention with suffix *Async but doesn't return a Task.

Please consider deprecating this method and come with a new methodname. The same applies to CancelAsync

Fixing it would not be possible because it's a breaking change.

Or... deprecate BackgroundWorker completely and come with an (better) alternative. For example one with async/await, cancellationtoken support etc. Would that be Task.Factory.StartNew or Task.Run?

svick commented 6 years ago

deprecate BackgroundWorker completely and come with an (better) alternative. For example one with async/await, cancellationtoken support etc. Would that be Task.Factory.StartNew or Task.Run?

According to Stephen Cleary, yes, Task.Run is the replacement for BackgroundWorker, see his series of blog posts where he compares the two.

Assuming the team agrees with that, I think it would make sense to make BackgroundWorker deprecated by adding it to the Platform Compatibility Analyzer.

kouvel commented 6 years ago

Is [Deprecated] still used for a build-time notification, for those who may bypass the analyzer?