1

Possible Duplicate:
How to use Progress bar during loading an xml File

I have an XML file and there are almost 200.000 records in the XML file.
I load those records to the DataTable like below.

string file = "C:\\records.xml";
DataTable dt = new DataTable();
dt.ReadXml(file);

when this process works application waits until loading data to datatable.
So, i want to use this time. And i want to show to user processbar while loading data to the datatable.
How can i do it?

Community
  • 1
  • 1
namco
  • 6,208
  • 20
  • 59
  • 83
  • Why you have to load 200.000 records into memory? – cuongle Nov 03 '12 at 06:56
  • There's only so much patience a user has to stare at a glacially incrementing progress bar. She'll put up with it for no more than 5 seconds and fires up Solitaire. Hide your user interface and use a NotifyIcon to display a balloon when the job got done. Using a handful of different icons that show progress is a nicety. – Hans Passant Nov 03 '12 at 10:22

1 Answers1

1

It is always better practice to do long blocking operations on a different thread, using a BackgroundWorker.

You can update the progressBar on the UI thread using the ReportProgress method. Here's an example.

Anirudh Ramanathan
  • 46,179
  • 22
  • 132
  • 191
  • Thanks for answer. But could you show an example please. – namco Nov 03 '12 at 07:00
  • @namco There is a link to an example in the answer. I didn't notice earlier, but your question seems to be the same as [this one](http://stackoverflow.com/questions/8099149/how-to-use-progress-bar-during-loading-an-xml-file-in-c) – Anirudh Ramanathan Nov 03 '12 at 07:00