Question

Sorry if it is a dumb question. I'm confused about the wait() and its variants in regards to the task parallel library.

Every single example I've seen waits on tasks to complete - is this considered good practice?

My scenario is this, that I'm developing a windows service that will run continuously. I would like to engage a number of tasks, but I don't care if they will run to completion - I will set a cancellation-token with an expiration, that will throw an error if something goes awry. So I don't see the need for a wait-to-complete, but every darn example uses it...

Was it helpful?

Solution

It really depends on what your situations needs. If for instance, you want to launch a sub process to do a procedure, say for instance, fire off an email in parallel you can do without waiting.

However, if you will need to act upon what ever result or structure which is affected by some behavior you will need to wait.

If your tasks are self contained and do not interact and/or depend on each other, then I do not see why you would need to wait.

OTHER TIPS

You only need to wait on a task if the code that is waiting requires the output of the task before it can proceed. If you don't need that output, don't wait.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top