Understanding Parallel Programming in C#

all are synchronous all wait for all actions n.w
1 / 12
Embed
Share

Dive into the world of synchronous actions, parallel processing, and asynchronous tasks in C#. Learn how to efficiently run multiple operations concurrently, optimize performance, and handle slow actions with practical examples and insights.

  • C# Programming
  • Parallel Processing
  • Asynchronous Tasks
  • Multithreading

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. All are synchronous = all wait for all Actions to execute in ThreadPool static void Parallel.Invoke(params Action[] actions) static ... Parallel.For(int fromInclusive, int toExclusive, Action<int> body) static ... Parallel.ForEach<T>(IEnumerable<T> source, Action<T> body)

  2. FastFoodRegularPork.csproj building restaurant FastFood cooking hiring oompa loompas HamburgerPatty MeatProcessingPlant grinding meat Pork building pig pen hamburger feeding pigs PigProducer Corn CropFarmer Images by brgfx & topntp26 & macrovector & Smashicons https://www.freepik.com/author/brgfx https://www.freepik.com/author/topntp26 https://www.freepik.com/author/macrovector https://www.flaticon.com/free-icons/mincer

  3. R = f1() + f2(); temp1 = f1(); temp2 = f2(); R = temp1 + temp2; slow slow

  4. Run slow action in parallel (or concurrently) task1 = f1Async(); temp2 = f2(); R = task1.Result + temp2; R = f1() + f2(); slow slow temp1 = f1(); temp2 = f2(); R = temp1 + temp2; slow slow

  5. Run slow action in parallel (or concurrently) task1 = f1Async(); temp2 = f2(); R = task1.Result + temp2; R = f1() + f2(); slow slow temp1 = f1(); temp2 = f2(); R = temp1 + temp2; slow slow task1 = f1Async(); temp2 = f2(); task1.Wait(); temp1 = task1.Result; R = temp1 + temp2;

  6. task1 = f1Async(); task2 = f2Async(); R = task1.Result + temp2.Result; task1 = f1Async(); temp2 = f2(); R = task1.Result + temp2; R = f1() + f2(); temp1 = f1(); temp2 = f2(); R = temp1 + temp2; slow slow task1 = f1Async(); temp2 = f2(); task1.Wait(); temp1 = task1.Result; R = temp1 + temp2;

  7. task1 = f1Async(); task2 = f2Async(); R = task1.Result + temp2.Result; task1 = f1Async(); temp2 = f2(); R = task1.Result + temp2; R = f1() + f2(); temp1 = f1(); temp2 = f2(); R = temp1 + temp2; slow slow task1 = f1Async(); temp2 = f2(); task1.Wait(); temp1 = task1.Result; R = temp1 + temp2; task1 = f1Async(); task2 = f2Async(); temp1 = task1.Result; temp2 = task2.Result; R = temp1 + temp2;

  8. task1 = f1Async(); task2 = f2Async(); R = task1.Result + temp2.Result; task1 = f1Async(); temp2 = f2(); R = task1.Result + temp2; R = f1() + f2(); temp1 = f1(); temp2 = f2(); R = temp1 + temp2; slow slow task1 = f1Async(); temp2 = f2(); task1.Wait(); temp1 = task1.Result; R = temp1 + temp2; task1 = f1Async(); task2 = f2Async(); temp1 = task1.Result; temp2 = task2.Result; R = temp1 + temp2; task1 = f1Async(); task2 = f2Async(); Task.WaitAll(task1, task2); R = task1.Result + task2.Result;

  9. task1 = f1Async(); task2 = f2Async(); R = task1.Result + temp2.Result; task1 = f1Async(); temp2 = f2(); R = task1.Result + temp2; R = f1() + f2(); temp1 = f1(); temp2 = f2(); R = temp1 + temp2; slow slow task1 = f1Async(); temp2 = f2(); task1.Wait(); temp1 = task1.Result; R = temp1 + temp2; task1 = f1Async(); task2 = f2Async(); temp1 = task1.Result; temp2 = task2.Result; R = temp1 + temp2; task1 = f1Async(); task2 = f2Async(); Task.WaitAll(task1, task2); R = task1.Result + task2.Result; static void Task.WaitAll(params Task[] tasks) static int Task.WaitAny(params Task[] tasks)

  10. FastFoodRegularPork.csproj building restaurant FastFood cooking hiring oompa loompas HamburgerPatty MeatProcessingPlant grinding meat Pork building pig pen hamburger feeding pigs PigProducer Corn CropFarmer Images by brgfx & topntp26 & macrovector & Smashicons https://www.freepik.com/author/brgfx https://www.freepik.com/author/topntp26 https://www.freepik.com/author/macrovector https://www.flaticon.com/free-icons/mincer

  11. Completed FastFoodPorkFromStock.csproj building restaurant cooking FastFood hiring oompa loompas ? Completed Completed future HamburgerPatty Task.FromResult<>() grinding meat MeatProcessingPlant ? Completed Completed building pig pen future Pork future Pork hamburger Task.FromResult<>() feeding pigs PigProducer ? Completed Completed future Corn future Corn Task.FromResult<>() CropFarmer Images by brgfx & topntp26 & macrovector & Smashicons https://www.freepik.com/author/brgfx https://www.freepik.com/author/topntp26 https://www.freepik.com/author/macrovector https://www.flaticon.com/free-icons/mincer

  12. Completed FastFoodFuturePork.csproj building restaurant cooking waiting ? Completed FastFood future HamburgerPatty future HamburgerPatty hiring oompa loompas promise promise .SetResult() grinding meat waiting ? Completed MeatProcessingPlant future Pork future Pork promise promise building pig pen hamburger .SetResult() feeding pigs PigProducer ? Completed Completed future Corn future Corn Task.FromResult<>() CropFarmer Images by brgfx & topntp26 & macrovector & Smashicons https://www.freepik.com/author/brgfx https://www.freepik.com/author/topntp26 https://www.freepik.com/author/macrovector https://www.flaticon.com/free-icons/mincer

Related


More Related Content