I have some code that I need to "fire and forget," in the sense that the calling code doesn't need to wait around for a response.
If I were to iterate a loop and call this 10,000 times in the span of a second, would I have 10,000 threads floating around, fighting for resources? I have a nightmare of my machine instantly slowing to a crawl.
Alternately, does the thread pool manage these requests, and queue them for resolution?
Put another way, how easy is it to do something stupid with Task.Run()
.
When you call Task.Run, you are queueing work to run in the thread pool. If you start a bunch of work, it can take a while to finish as you have limited computing resources. It's easy to bite yourself when running background tasks using Task.Run. It's best to understand the scenario and use the right tools for the job. If you're looking to process lots of background work, take a look at things like TPL, BlockingCollection and Concurrent Collections. Things like Producer/Consumer flows are the right direction, but all depends on what problem you're trying to solve.