Maxsteel
Maxsteel

Reputation: 2040

Best way of reading a csv and perfoming row wise action

I have a csv file of relatively small size(~2000 rows). I need to read each line and perform Web API calls. The method I opted for is very simple:

This method, even though works, is very trivial. Can you please tell me an efficient, faster method. I am not good in parallel programming in .Net/C#. Any pointers will be appreciated.

Note: I am not asking for exact code, I'm looking for an explanation on how this can be done but example with code is highly appreciated.

Upvotes: 0

Views: 158

Answers (1)

Ehsan
Ehsan

Reputation: 32729

If you have already written the method and only looking for parallism then you can use Task Parallel Library.

The Task Parallel Library (TPL) is based on the concept of a task, which represents an asynchronous operation. In some ways, a task resembles a thread or ThreadPool work item, but at a higher level of abstraction. The term task parallelism refers to one or more independent tasks running concurrently. Tasks provide two primary benefits: More efficient and more scalable use of system resources. Behind the scenes, tasks are queued to the ThreadPool, which has been enhanced with algorithms that determine and adjust to the number of threads and that provide load balancing to maximize throughput. This makes tasks relatively lightweight, and you can create many of them to enable fine-grained parallelism. More programmatic control than is possible with a thread or work item. Tasks and the framework built around them provide a rich set of APIs that support waiting, cancellation, continuations, robust exception handling, detailed status, custom scheduling, and more.

However, if you want your code to be optimized then you will have to post your code. A very good CSV reader is already present here.

Upvotes: 1

Related Questions