Reputation: 1525
I had a SQL Stored Procedure that get a mbd file and import it using itself in less than 3 second but because of the security of the shared server I can't do it anymore but instead I can use vb.net to import necessary temp tables to Sql server and continue the process
Unfortunately it gets so long to complete the process (about 3 minutes for a 3MegaByte mdb file), and I need to show client the process so the client can wait patiently and know how far the process has gone.
I have seen many things related to this but they are all showing an image loading instead of exact progress bar,
My question is: Is there any possible way to show the progress bar while based on how the process is doing?
PS: I can place the show progress percent in my for loop in vb.net.
EDIT: To be specific I just need to know how can I show the client the progress and just update the progress bar in html or maybe change the progress bar width style?
Thanks
Upvotes: 0
Views: 2981
Reputation: 10456
You can use a BackGroundWorker
:
When using backgroundWorker, it is always convenient for me to use @Keith template
BackgroundWorker bw = new BackgroundWorker { WorkerReportsProgress = true };
bw.DoWork += (sender, e) =>
{
//what happens here must not touch the form
//as it's in a different thread
//Here you should call the function that does the heavy, slow work.
//pass the BackgroundWorker instance (bw) as an argument
};
bw.ProgressChanged += ( sender, e ) =>
{
//update progress bars here
};
bw.RunWorkerCompleted += (sender, e) =>
{
//now you're back in the UI thread you can update the form
//remember to dispose of bw now
};
worker.RunWorkerAsync();
In you function update about the progress by using something like:
void YourFunction(BackgroundWorker bw)
{
for (int i = 0; i < length; i++)
{
//do your work
int percent = (i / length) * 100;
bw.ReportProgress(percent);
}
}
Upvotes: 1