Progress Bar

  • Thread starter Thread starter Reggie
  • Start date Start date
R

Reggie

Hi and TIA! When uploading files I would like to show a progress indicator
as to what's going on. Currently the user clicks the button, the file gets
uploaded, but there's no visual indication that the upload has even begun.
Any advice or guidance is appreciated. Thanks for your time
 
Hi Reggie!

File uploading in itself is an atomic task so there are only 3 types of
events that are possible with such configuration:

1) Upload Start Event
2) Upload Complete Event
3) Upload Interrupted/Aborted Event

NOTE: Its also quite possible that api is configured to raise events
based on its internal state i.e. raise a event where every 10% of the
bytes get uploaded.

What ever the case there be, what you need to do is to register event
handlers for the events and then in the event handlers perform action
(as mentioned below);

private void RegisterFileUploadEvents()
{
// Register File Upload Event
FileUploadLibrary.UploadStarted +=
new EventHandler(fileupload_started);
// Register File Complete Event
FileUploadLibrary.UploadComplete +=
new EventHandler(fileupload_complete);
// Register Abort Event
FileUploadLibrary.UploadAborted +=
new EventHandler(fileupload_interrupted);
}

private void fileupload_started(object sender, EventArgs e)
{
this.StepProgressBar();
this.MaterializeToStatusBar("File upload has started");
}

private void fileupload_complete(object sender, EventArgs e)
{
this.StepProgressBar();
this.MaterializeToStatusBar("File upload complete");
}

private void fileupload_interrupted(object sender, EventArgs e)
{
this.StepProgressBar();
this.MaterializeToStatusBar("File upload has been interrupted. Please
try again later");
}

and your "StepProgressBar()" and "MaterializeToStatusBar(...)" will go
like this:

private void StepProgressBar()
{
if (this.progressBar1.Value < this.progressBar1.Maximum)
{
this.progressBar1.Value += this.progressBar1.Step;
}
}

Note: You can set the "Maximum/Step" properties from properties window

private void MaterializeToStatusBar(String message)
{
this.lblStatusMessage.Text = message;
this.Refresh();
}

At times, Timer Control is also used to tick the status bar.

I hope this might be of some help.

Let me know in case of any inconsistancy.

Regards,

Moiz Uddin Shaikh
Software Engineer
Kalsoft (Pvt) Ltd
 
Back
Top