I am using FileInfo method CopyTo to copy some large files. I am using BackgroundWorker to do this in a separate thread.

The problem is that I would like to update a progress bar, but I can only update that between each file copy which is not often enough. There is also a similar problem with CancellationPending (and I don't know how to cancel the ongoing CopyTo without killing the thread).

What is the best option here? The most obvious is to copy the files in smaller chunks instead of using CopyTo. That would be ok, but I don't want to lose any performance (e.g. dma not being used efficiently).

One more thing:

The files will usually be on separate disks. So if I copy it chunk by chunk it is probably not a good idea to read-write-read-write etc. because that means only one of the disks would perform something useful at any time. Instead I would need a read thread and a write thread that needs to share a buffer and wait for each other when the buffer becomes full or empty. Not extremely hard, but not what I planned to use my time for...

What functions should I use to read and write chunks? FileStream Read and Write takes an int as offset, so I don't expect them to work for files larger than 2 GB. (Not an issue in this case since the files are 1 GB, but I would like to make it right from the start.)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.