Im developing an application, and one of its functions is to read files.
i want to add a progress bar which indicates how many precents of the file have been read.
the problem is that with big files the program hangs until the operation is completed, and no info is shown in the progress bar.
im working with j#.net but it can happen in any language.
heres a bit of the code:
the problem is when im trying to update the progressBar with set_Value(), it just doesnt work.
thanks for your help.
i want to add a progress bar which indicates how many precents of the file have been read.
the problem is that with big files the program hangs until the operation is completed, and no info is shown in the progress bar.
im working with j#.net but it can happen in any language.
heres a bit of the code:
Code:
public void readFile(String fileName)
{
FileStream fs =new FileStream(fileName,FileMode.Open);
long fileSize = fs.get_Length();
fs.Close();
StreamReader reader = new StreamReader(fileName);
//the form where the progress bar is:
progressWindow.Show();
int bytesRead = 0; //number of bytes that have been read.
char buf = \0; //buffer
while (reader.Peek() != -1) //while not at the end of the file...
{
buf = (char)(reader.Read());
/*...*/
bytesRead++;
//update the progress bar:
progressWindow.progressBar.set_Value((int)((bytesRead/fileSize)*100));
}
reader.Close();
writer.Close();
progressWindow.Hide();
}
the problem is when im trying to update the progressBar with set_Value(), it just doesnt work.
thanks for your help.