Click here to Skip to main content
14,360,161 members
Rate this:
Please Sign up or sign in to vote.
I am new to C# and working on a project. The project reads the multiple .csv files (in a folder) and parse them and show the results in the windows application. Although it processes the files very slow. So i had to ask can i use multithreading for reading files Or is there any other technique which i can implement to make the reading and parsing the files and showing the results fast?

What I have tried:

Using the simple methods to reading and parsing files
Updated 8-Nov-19 4:43am
Rate this:
Please Sign up or sign in to vote.

Solution 2

Multithreading is not guaranteed to make a great difference, and will depend on what your code is doing. The first thing to look at is where the slow processing actually occurs. Is the delay due to the speed of getting the data off disk, or in processing it once it's in memory?
Member 14646256 4 days ago
If the delay is due to the processing once it is in memory, is there any other solution which you can recommend?
The program reads the csv file, parse it and show details, and then it does same for next file, in this way it reads all files in the folder. So is it also possible that i first read all files, parse and then show details of all at once? Is it possible?
Richard MacCutchan 3 days ago
You cannot work on a solution until you know where the delay is. Run some timing tests to find out where the program spends most time. Only then can you start working on improving performance.
Rate this:
Please Sign up or sign in to vote.

Solution 1

I would recommend using Task.Factory, see example here: Whats the best way of asynchronous parsing a CSV file in c# - Stack Overflow[^]
Rate this:
Please Sign up or sign in to vote.

Solution 3

File size, the number of files and what you're doing to the data are all primary factors. Only you can determine the sweet spot, or if you should even implement any kind of threading.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100