show progress while copying big file

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

is it possible to show the progress of a big file being copied e.g. in
a "progressbar"?
I tried to use file.copy - but this seems to make no sense :-(

Thanks in advance,

Randy
 
to do a proper progress bar, and provide button to cancel etc. you'll need
to do the file copying in a seperate worker thread.
you can then fire events from there back to your form containing the
progress bar to report progress.

in a nutshell, you need to keep the UI responsive whilst the copying is
taking place.

look in to making a worker thread, it's not too difficult, and then look
into calling control's methods from another thread - this too is easy to do.

HTH
Sam
 
Randy,

If you want to show the standard progress bar, then you will want to
call the SHFileOperation API function through the P/Invoke layer.

Hope this helps.
 
Dear All,

i am building a pocket pc program that will be copying a large file
from across a network. I am trying to show a progress bar for the file
being copied
can anyone tell me how to update the progress bar to reflect the
status of the copy process.
I am using system.io.file.copy
Please tell me step by step,

Best regards,

Mohamed Oubouchil
 
C# not provide solution for this. You can use either Managed FileCopyEx
implementation or SHFileOperation. Refer MSDN for how to
 
I think my question was not clear. Here is a simpler scenario. If I want to
show text "Finished!" on myLabel1 on Form1 from Class1, how should I do it?
If I do this from the code behind of Form1, I can just write myLabel1.Text =
"Finished!", but I don't know how I can do this from Class1.
 
The following example is in your main form. This can be called from your
main form *or from another thread which can be your class1. You just need
to pass the form ref to your class constructor or set a public static or
something so that class1 knows how to reference
"Form.UpdateDelegate("sometext");" (for example.) Note the InvokeRequired
and delegate stuff is there to make any calls from other threads are queued
to UI thread as you should not call UI controls from other threads.
Moreover, you can use this method to update any control in your forms
(pBars, etc.) Just create the right delegate and use the UpdateLabel
template as example for you new method. hth

private delegate void UpdateDelegate(string value);

public void UpdateLabel(string text)
{
if ( text == null )
throw new ArgumentNullException("text");

if ( InvokeRequired )
{
UpdateDelegate ud = new UpdateDelegate(UpdateLabel);
this.BeginInvoke(ud, new object[]{text});
}
else
{
this.label1.Text = text;
}
}
 
William,

Thank you for the info. This is really helpful.

Tomtom

William Stacey said:
The following example is in your main form. This can be called from your
main form *or from another thread which can be your class1. You just need
to pass the form ref to your class constructor or set a public static or
something so that class1 knows how to reference
"Form.UpdateDelegate("sometext");" (for example.) Note the InvokeRequired
and delegate stuff is there to make any calls from other threads are
queued
to UI thread as you should not call UI controls from other threads.
Moreover, you can use this method to update any control in your forms
(pBars, etc.) Just create the right delegate and use the UpdateLabel
template as example for you new method. hth

private delegate void UpdateDelegate(string value);

public void UpdateLabel(string text)
{
if ( text == null )
throw new ArgumentNullException("text");

if ( InvokeRequired )
{
UpdateDelegate ud = new UpdateDelegate(UpdateLabel);
this.BeginInvoke(ud, new object[]{text});
}
else
{
this.label1.Text = text;
}
}

--
William Stacey, MVP
http://mvp.support.microsoft.com

TomTom said:
I think my question was not clear. Here is a simpler scenario. If I want to
show text "Finished!" on myLabel1 on Form1 from Class1, how should I do it?
If I do this from the code behind of Form1, I can just write
myLabel1.Text =
"Finished!", but I don't know how I can do this from Class1.
 
Back
Top