Progress bar while importing, best practice

S

Søren Reinke

Hi there

I am working on a program where the user should be able to import some CSV
files.

With my set of test data, it takes about 2 minutes to import, while it is
importing the program sort of freezes.

Therefore i would like to open a little window with a progress bar in it
that shows how far the import has come.

What is the best practice for doing this ?
I have a class with the CSV import parser in it, with one method doing
everything (of course it calls other methods as will).

So should i let the form with the progress bar call the import class ?

Another question regarding this import is, at the moment i fill all the data
into 2 tables in a dataset, and store it in a JET database when the import
is finish, would it be best to store it one record at a time ?

Hope my questions makes sense :)
 
M

Maqsood Ahmed

Hello,
First of all it should not freeze the interface. CSV importing should
be done in a worker thread, you can use Invoke method to update the
progress bar on the basis of amount of data you have processed. Now its
upto you that you open a new window and display the progress bar or
display it at the same form where you have started the process.

HTH. Cheers.
Maqsood Ahmed [MCP,C#]
Kolachi Advanced Technologies
http://www.kolachi.net
 
S

Søren Reinke

Hello
First of all it should not freeze the interface. CSV importing should
be done in a worker thread, you can use Invoke method to update the
progress bar on the basis of amount of data you have processed. Now its
upto you that you open a new window and display the progress bar or
display it at the same form where you have started the process.

I am quite new to .net programming, might you have a little example on how
to do that in a workerthread ?

Would you suggest the calling class opens a form window with the progressbar
in it, then starts a workerthread who then updates the progress bar ?

--
Søren Reinke
www.Xray-Mag.com/ - Your free diving magazin on the net.
Current issue Diving in North America, 99 pages.
Download it in PDF
HTH. Cheers.
Maqsood Ahmed [MCP,C#]
Kolachi Advanced Technologies
http://www.kolachi.net
 
M

Michael McCarthy

As said, you need to move your import code (and any other code that puts
a tax on the system) into another thread that runs asyncronously.

One thing I'll mention is that as far as progress bars go, it has to
report "some" progress... not necissarily thee progress... What I mean
is that, for example, most of the time in async web calls you are only
getting an indication that progress is being made, but not the exact
ammount of progress because that isn't always known.


Here's the text I put in a similar thread:

You can either set up an IAsync, which I think is painful and a lot of
work, or you can add a backgroundworker control (2.0), and the
workercompleted even will fire when its done... (you can do whatever you
want in that time, including being idle)...

one page with a few references to the background worker control is here:
http://weblogs.asp.net/rosherove/archive/2004/06/16/156948.aspx

this one is also popular:
http://www.mikedub.net/mikeDubSampl...eallySimpleMultithreadingInWindowsForms20.htm

or this is a fairly good video on IAsync by Mike Taulty:
http://www.microsoft.com/uk/asx/msdn/nuggets/asynchronouswebservicecalls.asx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top