I have an application in which I upload a file to blocks. My external interface is WPF, and I have a progress bar showing the progress of downloading the file (the download is done in a separate thread, and the progress bar is in a separate form called by the child thread when the download starts).
I found the total number of blocks in the file to set the maximum progress bar property.
Now for each loaded block, I increase the value of the progress bar by 1.
But, to my surprise, the progress bar starts to increase, but never ends (it stops showing progress after several blocks).
Here is the code for the stream responsible for downloading the files:
System.Threading.Thread thread = new Thread (
new ThreadStart (
delegate ()
{
// show progress bar - Progress is the name of window containing progress bar
Progress win = new Progress ();
win.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
win.Show ();
// find number of blocks
long BlockSize = 4096;
FileInfo fileInf = new FileInfo (filename);
long FileSize = fileInf.Length;
long NumBlocks = FileSize / BlockSize;
// set the min and max for progress bar
win.Dispatcher.Invoke (
new Action (
delegate ()
{
win.progressBar1.Minimum = 0;
win.progressBar1.Maximum = NumBlocks;
}
), System.Windows.Threading.DispatcherPriority.Render);
// upload file
while (true)
{
// code to upload the file
win.Dispatcher.Invoke (
new Action (
delegate ()
{
win.progressBar1.Value + = 1;
}
), System.Windows.Threading.DispatcherPriority.Render);
}
}
Can someone help me analyze why this is happening.
Thanks.
source share