Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the benefit of using the Thread.Sleep method in a backgroundworker?

Wherever I see examples of using the BackgroundWorker in .NET I see people adding Thread.Sleep(int). Maybe I am missing something, but what's its benefit if you don't want to wait? Wherever I use BackgroundWorker I am performing lengthy operations which I want them to be completed as soon as possible.

like image 572
Panos M Avatar asked Nov 20 '25 13:11

Panos M


1 Answers

If you don't want to wait, there isn't one. People may be using this to share time between other threads as @the_lotus commented.

Also, since you mentioned seeing this in examples, you have probably witnessed someone deciding to type one, easy to comprehend line in their tutorial rather than generating enough code that it actually takes long enough to run to demonstrate the background worker.

like image 71
Josh Avatar answered Nov 22 '25 04:11

Josh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!