Help Needed in Multi Threading

Born2Achieve 21 Reputation points
2021-04-26T02:19:07.907+00:00

Hello Friends,

I have an requirement that have 100*1000 pdf documents stored NAS and Will need to get the documents from NAS and upload it to Google Cloud. I will need to do this in Multi-threaded.

Can I write this multi-threaded download from NAS and upload to Google cloud in .net core API or .net core Console app. Which is best approach and is Parallel.foreach can be used for multi threaded else any other best approach?

Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Daniel Zhang-MSFT 9,666 Reputation points
    2021-04-26T05:31:51.56+00:00

    Hi karthikeyanmuthusamy-5280,
    When you perform any batch tasks, Parallel.foreach is a better choice.
    Parallel.ForEach loop in C# runs upon multiple threads and processing takes place in a parallel way. Its execution is faster than foreach in most of the cases.
    Parallel.ForEach loop is not a basic feature of C# and it is available from C# 4.0 and above.
    More details please refer to the following links
    Parallel.ForEach Method
    How can I convert this foreach code to Parallel.ForEach?
    Best Regards,
    Daniel Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.