You will need to call CopyFileEx
from the background thread. Currently, a CopyFileEx
call blocks the user interface thread. Therefore, the user interface is not updated.
The callback action is indeed called repeatedly. This means that you can inform the user about the progress with a long file.
To be clear, this happens when you call CopyFileEx
:
Enter CopyFileEx Start copying Call your callback Continue copying Call your callback .... Return from CopyFileEx
During the entire time the file is copied, the executable stream is busy copying the file, not pumping the message queue. Although these are WinForms, not Win32, WinForms is a relatively lightweight shell around the standard Win32 GUI. Your message queue should be serviced regularly, so all lengthy tasks should be removed from the user interface thread.
One final point: remember that when you get a progress callback, you need to use Invoke
or BeginInvoke
when updating any user interface. This is because the code updating the interface must be run from the user interface thread.
source share