locked
Multi threading or Task or Parallel RRS feed

  • Question

  • User-1256377279 posted

    Hi Guys,

    I have 2 method which takes approximately 40 sec each, Please can you help to find best way to run whether should i  use MultiThreading / Task / Parallel.

    Below are my Methods

      bool MandatValidate = oImport.ValidateMandateLoad(noOfRow, workSheet, ref importlistmandat, ref sb);
                                    
    
      bool NonMandatValidate =  oImport.ValidateNonMandateLoad(noOfRow, workSheet, ref importlistnonmandat, ref sb);

    Many Thanks 

    Shabb

    Friday, February 1, 2019 12:49 PM

Answers

All replies

  • User475983607 posted

    I have 2 method which takes approximately 40 sec each, Please can you help to find best way to run whether should i  use MultiThreading / Task / Parallel.

    It's not possible due to the ref inputs. Your question infers that throwing treads at a performance problem will fix the problem .  It will not.  Multithreaded application require upfront design.  I recommend learning the basics.

    https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/async/

    Friday, February 1, 2019 1:17 PM
  • User753101303 posted

    Hi,

    It seems you are scanning the same data twice (each time with a different criteria) ? You can't validate data in one go ?

    Before looking at this, I would first make sure there nothing that can be done quite easily to optimize the current code (and would look at where this time is spent exactly).

    Friday, February 1, 2019 1:20 PM
  • User-1256377279 posted

    Hi Patrice,

    Yes it make sense, My main concern is not performance i will try to improve internally. My question was how we can run 2 method simultaneously and how to get boolean result whether both the method have successfully completed or not.

    Many Thanks,

    Shabbir

    Friday, February 1, 2019 1:39 PM
  • User475983607 posted

    Yes it make sense, My main concern is not performance i will try to improve internally. My question was how we can run 2 method simultaneously and how to get boolean result whether both the method have successfully completed or not.

    Again, the "ref" inputs make this impossible.  

    Friday, February 1, 2019 1:44 PM
  • User753101303 posted

    And there is AFAIK no magic bullet. You still need to understand where this time is spent (and in particular if it is CPU or I/O bound) and design things so that it could work (and possibly efficiently). One level up you have https://docs.microsoft.com/en-us/dotnet/standard/parallel-processing-and-concurrency

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, February 2, 2019 12:28 PM
  • User-1256377279 posted

    Thanks ParticeSc for your kind comment, I will look into it.

    If you have any links to Implement Threading / Task / Parallel programming please do share 

    Many Thanks,

    Shabbir

    Monday, February 4, 2019 9:33 AM
  • User475983607 posted

    If you have any links to Implement Threading / Task / Parallel programming please do share 

    See the previous posts.

    Monday, February 4, 2019 12:17 PM
  • User-1256377279 posted

    Thanks got it 

    Monday, February 4, 2019 2:03 PM