Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying progress when using BinaryWriter.Write()

Status
Not open for further replies.

djfrear

Programmer
Jul 11, 2007
83
GB
I have declared an instance of BinaryWriter and am using this to write to a file. I am also using BinaryReader to read etc.

Simple stuff. The main issue is that I will be dealing with large files and wish to show some sort of progression as user output, preferably using a progressbar.

The issue here is that the class itself (BinaryWriter/Reader) is doing all the work in the background and I only have the 1 line of code which does all the legwork, e.g:

int read = inputData.Read(data, offset, dataRemain);

In this case all the data is read into the byte buffer (data) in one go. The only way I can think of is to have the buffer split the work into smaller chunks and process each one as it comes in, but this may impact speed.

Is there any way to show progress of something like that without putting it in a loop and incrementing a progress bar after each "chunk" is read/written?

Regards, Daniel.

IT Support Tech.
BSc (Hons) Software Engineering
 
i think probably the easiest way is to look at Ajax for asp.net.



you put your buttons and lables etc into the update panel, then you can add a progress panel. in this progress panel you put an animated gif to show that work is being done.

It's really easy to implement and use. b sure to look through one of the tutorials, so set up the web config correctly.
 
Hey Nick,

Im not actually using ASP.NET, just C#. Good idea though, pity there isnt anything like that for C# (that i know of).

Regards, Daniel.
 
oh so it's a windows form.. not entirely sure if u can show animted gifs on forms.. but show and hide this images before and after.

it's all about giving the user some sort of feedback that something is working, like a swirling image then not seeing anything at all..
 
Yes possibly, I was hoping for some sort of progress rather than just showing that something is actually happening.
 
You can run an animated gif on a form no problem. Just open the image in the Image control and it will play automatically. As an added note though, make sure you call Dispose() on the image when your form closes - otherwise the form may not close properly.



 
looks as though this may end up being the best solution so far then, so thanks for the idea Nick.

Regards, Daniel.
 
Just a note to let you guys know that I solved the problem by creating a buffer and reading into that buffer, writing that data, then repeating. This slows the code down a little, but it allows for a proper progress bar and the ability to estimate time remaining.

This was essential for me, and so I can deal with the slight slowdown.

Regards, Daniel.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top