Question binary file read operation

euromax

Member
Joined
Apr 19, 2009
Messages
7
Location
Mauritius
Programming Experience
Beginner
Hi
I have a windows form which to summarize lets the user open a file containing 32 bit hashes, then search for one of them. The hash is then converted to its string representation.
The application is giving the results I would expect but I'd like to make it execute faster than it does now; some files can be pretty big > 100 MB. I'm doing the file read using a BackgroundWorker object to display progress updates and ensure that the UI is available during the process. But for that i need to add a System.Threading.Sleep(1) instruction in the loop; otherwise the application freezes with big files. And System.Threading.Sleep(1) creates a noticeable lag..
Any suggestions on how to make searches fast without freezing the UI? Getting speeds comparable to hex editor programs for example.
If source code is required i can post.
 
Perhaps you're generating too many progress events? For example it is not necessary to send 10000 progress updates for each percent change.
 
thanks!

Yes good point JohnH you are right! Too many progress updates. As well as excessive System.Threading.Sleep(1) calls. For every 5kb I was doing 1250 of them (5000/4; i'm reading Int32) which implies a 1.25s lag.

Now I'm getting reasonable speeds and here's the modified function. Progress updates and sleep(1) calls are only performed when %progress changes by 5%

PS: hope you don't mind my posting c# code on a vbdotnet forum.
 
hope you don't mind my posting c# code on a vbdotnet forum.
Why would you need to do that? If you're working on C# and need help with code here you can use an online code converter to get something usable to present at VB.Net forums.
 
Back
Top