views:

163

answers:

5

I have a C# win form where I read a file and show lines in a datagridview. Everything works fine.. and I use delegate and Invoke for displaying the lines as they are being read. It also shows a progressbar and does some other stuff like calculating line length and parse the lines to extract certain fields from each line.

Just curious, if anybody has tried this kind of implementation. Currently my app reads a 250MB file (having ~ 12000 lines) in little over 3 minutes (Win 7 32bit/celeron 2.66Ghz/4GB). I was wondering if it is possible to reduce the time - more of like by changing the way I implemented it.

+1  A: 

If you want to improve the performance of loading your file, your going to have to post the code that loads it.

Alex Spence
+1  A: 

Ok...I love these questions. Why are you showing a user 250mbs of data in a data grid? There is NO WAY that an end user can process understand 250mbs of data in a grid. If the end user is pressuring you for this feature you need to address it with them from a "this is a bad idea" standpoint. Performance problems can usually be solved in most cases by educating the user. :-D

Achilles
Answer I got while trying this: "I can understand why you say it is a bad idea, but I still want it and with thye best performace possible."
Wilhelm
Yeah man and then you will get asked to change it later lol.
Achilles
+1  A: 

Well, you're quite right to have second thoughts about this. What's probably the toughest read possible, War and Peace by Tolstoy, has roughly half a million words. What you're dumping to the screen is a hundred times more. It doesn't really matter how long it takes to put this much info on the screen, it will take your user a wholeheckofalot longer to even scroll through it.

I personally hesitate to ever put anything more than, oh, 50 items in a list. 100 tops. Beyond that, it becomes sheer torture for a human being.

To get there, allow your user to filter content, gradually drilling down in the huge result set to a relevant item. Exactly what that ought to look like is not clear from your question. Think about it for a bit, I'm sure you'll come up with something.

Hans Passant
A: 

First, you need not load the entire file, nor display it. You can load portions of it for display. i.e. in the grid, you cannot show the enire file anyway, the screen is only so big. Consider loading only what you display (plus a few extra lines for smooth scrolling) and load the rest on demand as the user is scrolling through the content. The user will be unaware that the file is only partially loaded.

Even nicer would be if you have some logical grouping, in a book you could display the chapters, in a financial type application, either by account or time period.

MaLio
A: 

Maybe something like VirtualMode can helps you:

Virtual mode is designed for use with very large stores of data. When the VirtualMode property is true, you create a DataGridView with a set number of rows and columns and then handle the CellValueNeeded event to populate the cells. Virtual mode requires implementation of an underlying data cache to handle the population, editing, and deletion of DataGridView cells based on actions of the user. For more information about implementing virtual mode, see How to: Implement Virtual Mode in the Windows Forms DataGridView Control.

P.S. About performance: no one except profiling tool can't helps you to solve any performance-related problems.

Sergey Teplyakov