Nice post by the way. Set a string = nothing. That does exactly what it looks like. Nothing. Learn some more and post back.
Edited by Ezzaral: Removed offensive content.
Unhnd_Exception, I am what "I" am,
Nothing Else .
Heres an example of how the actual code makes a difference. VB.net is plenty fast. Most things can be improved just by changing the code.
I wouldn't call it an improvement because you now have a choppy progress bar that would update every 5 percentages. Would it call an improvement if I have a progress bar that would update itself every 100 percentages?
What I can see from your code is that you are trying to over-complicate yourself. You have used 100 extra bytes and using a very expensive arithmetic, Modular. Then, you introduced an unnecessary conditions
PercentComplete = CInt((TotalBytesRead / TotalBytesInFiles * 100)) If PercentComplete < 0 Then PercentComplete = 0 ElseIf PercentComplete > 100 Then PercentComplete = 100 End If
TotalByresInFiles are both positive integer. There is no way that a positive integer divided by a positive integer producing a negative integer and the only thing that smaller than 0 is negative number.
TotalByteRead is smaller than or equal
TotalByresInFiles . There is no way that
TotalBytesRead / TotalBytesInFiles * 100 will be larger than 100 even after you round up.
This applies to the example I provided in the other thread.
50 / 1000 = .05 * 100 = 5%
51 / 1000 = .051 * 100 = 5.1% but CInt(5.1) = 5
52 / 1000 = .052 * 100 = 5.2% but CInt(5.2) = 5
You can see 5% can be created many different ways so the progress bar is being updated unnecessary.
You are partly right. It is not necessary to re-draw progress bar if the value is unchanged. Moreover, if progress bar is small and short, 5.1% and 5.6% of progress bar make no significant different. Imagine that your progress bar is long which a 0.5% of the progress bar width could make a different. Then, you would think differently.
But you might argue that Progress Bar value only take Integer, it wouldn't be possible to have 5.5% of progress bar. Maybe you can increase the Maximum value higher.
Another thing is that casting a float-point number to integer (in VB.NET) will require a Round half in to even.
So what is my suggestion?
PercentComplete = CInt((TotalBytesRead / TotalBytesInFiles * 100))
This is not necessary. It use division operation and a multiplication operation repeatedly inside your loop. Division is averagely two times slower than multiplication. Multiplication is averagely four to five times slower than addition and subtraction.
Why don't you just set maximum value of the progress bar to
TotalBytesInFiles and set the value of progress bar according to
TotalBytesRead . It would take you less code and somehow faster. It is also solving the problem that I raised above about displaying 5.5% different from 5.1%.
Then, you might argue that it will update unnecessary and re-draw the progress bar is also an expensive thing to do as well. You are right and your idea of having to check whether the value has changed significant enough for progress bar to make an update is fantastic (you got my thumb up). However, you can further improve your implementation by eliminate extra array of boolean and avoiding using expensive operation.
'' Progress will be updated every 1%. If you want your '' progress bar to updated every 0.5%, You can change it '' to TotalBytesInFiles / 200 Dim SignificantStep As Integer = TotalBytesInFiles / 100 Dim currentStep As Integer = SignificantStep
Inside your background worker
If TotalBytesRead >= currentStep Then '' Whatever code that will update progress bar. currentStep += SignificantStep End If
I always like to have a meaningful discussion and open for it. Correct me if I am wrong or ask me if you are not clear of any of my point.
Edited by invisal: n/a
if not i remember Daniweb = Family then
Daniweb = Family vs Family <<<WRONG>>> You guys have serious EGO issues
Remember there's always a better hacker or Programmer
That's how it just is.
Don't brake someone down if he / she is wrong
Just correct him / Her and do it nicely :)
Btw im not taking anybody's side
Just Pointing something out :)
Edited by VB 2012: n/a
i want to print a persian file by thermal printer..
i can print an english file esily..but i face the proble while printing persian text..
i think i ...
I am working on program that will connect to MySQL database, colect data from table and show them in grid. Where user can edit cell, and then on ...
I'm coding a program to learn OpenGL in C++ (based off of The Benny Boxes tutorials) and I've run into a snag where I don't get any errors, but my ...