Suppose concurrently I want to do many tasks, like digging, cleaning, and so on. So this can be done using the Parallel.Invoke static method. This method will allow me to add various operations and execute them concurrently in parallel.
- private void OtherTask()
- {
- //Some task
- }
- private void Digging()
- {
- //Some task
- }
- private void CleanIt()
- {
- //Some task
- }
- public void CallAllTask()
- {
- Parallel.Invoke(
- new Action(OtherTask)
- , new Action(Digging)
- , new Action(CleanIt));
- }
The code snippet above will execute all of the list of operations in parallel.