R
Rich P
Using the following code I am downloading a (large) file. I fill a byte
array and use a filestream to write the contents of the byte array to
the disk. I am also using a backgroundworker thread. How can I monitor
the download progress? I call ReportProgress from the
backgroundWorker2.IsBusy loop. But how do I determine the end portion
of the operation? I know the file size, but when looking at Windows
Explorer - the file doesn't appear until the process is finished. How
can I monitor the amount of data being written to the disk at some given
time so that I can display the progress in a progress bar? Do I
physically monitor the file size on the disk as it grows - with say a
fileInfo object in the backgroundWorker2.IsBusy loop - something that I
can't see until the operation is completed?
---------------------------------------
WebClient request = new WebClient();
request.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
byte[] fileData = request.DownloadData(ftpServer + "/" + fileName);
FileStream file = File.Create(filePath + "\\" + fileName);
file.Write(fileData, 0, fileData.Length);
file.Close();
---------------------------------------
int i = 0;
while (backgroundWorker2.IsBusy)
{
backgroundWorker2.ReportProgress(i, "x");
i++;
Thread.Sleep(100);
Application.DoEvents();
}
array and use a filestream to write the contents of the byte array to
the disk. I am also using a backgroundworker thread. How can I monitor
the download progress? I call ReportProgress from the
backgroundWorker2.IsBusy loop. But how do I determine the end portion
of the operation? I know the file size, but when looking at Windows
Explorer - the file doesn't appear until the process is finished. How
can I monitor the amount of data being written to the disk at some given
time so that I can display the progress in a progress bar? Do I
physically monitor the file size on the disk as it grows - with say a
fileInfo object in the backgroundWorker2.IsBusy loop - something that I
can't see until the operation is completed?
---------------------------------------
WebClient request = new WebClient();
request.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
byte[] fileData = request.DownloadData(ftpServer + "/" + fileName);
FileStream file = File.Create(filePath + "\\" + fileName);
file.Write(fileData, 0, fileData.Length);
file.Close();
---------------------------------------
int i = 0;
while (backgroundWorker2.IsBusy)
{
backgroundWorker2.ReportProgress(i, "x");
i++;
Thread.Sleep(100);
Application.DoEvents();
}