A benefit? No, it is just a stab for a stop on 0 milliseconds
. Maybe, it is useful to dynamically change the delay. But I don't know a useful case for it.
Harm? Not big, just a few OS instructions to make the stop and keep it on. No result but some additional work.
BackgroundWorker by its definition is for heavy/long tasks that shouldn't block UI (block elements, fill your form with a single color, ...). That
slightly less responsive
behavior comes from the heavy task in the background. Your machine still has the same OS/RAM/CPU that should be shared between all of your threads and tasks. If your machine is out of free resources then existing ones will be shared in time. Kind of an additional big player that pushes existing ones.
Update. As properly noticed Solomon Slow, Sleep(0) is an equivalent for Yeld() (pass execution to another thread that is ready to run on the current processor). So it COULD slow your BG process, make it work longer.
Update on EDIT. Having the background process (another thread) already unblocked your UI. To separate these threads even more - you can try a Thread's Priority
property: https://learn.microsoft.com/en-us/dotnet/api/system.threading.thread.priority .
For example, assign a ThreadPriority.BelowNormal
value at your back ground thread while your main thread will have it ThreadPriority.Normal
.
Btw, BackgroundWorker has no such field or control. It has the same priority as your UI one. If you'll need such priority control - replace it with new Thread(...)
.
The change will drop BackgroundWorker's implemented result processing events such as ProgressChanged
, RunWorkerCompleted
. If you use them then you can implement firing similar events from your Thread on your own.