File Copy w/ Progress bar - Why so Slow??? - ALMOST RESOLVED
ok, im trying to do a filecopy progress bar, it copies the file fine, but it is SOOOOOOOOO slow while copying the file, and once the file is done copying it takes about 30 seconds to release the files
Any suggestions?
The form has 2 text boxes, one frame, one progressbar, and the command button
VB Code:
Private Sub Command1_Click()
Dim MyBytesa As Byte
Dim MyBytesb As Byte
Dim counter As Integer
Source = "C:\test.zip"
Dest = "c:\testfolder\test.zip"
Open Source For Binary As #1
Open Dest For Binary As #2
ProgressBar1.Max = FileLen(Source) / 1024
Text1.Text = FileLen(Source)
Do Until EOF(1)
counter = 0
MyBytesa = Empty
MyBytesb = Empty
Do Until (EOF(1)) Or (counter = 100)
Get #1, , MyBytesa
Put #2, , MyBytesa
counter = counter + 1
Loop
Text2.Text = FileLen(Dest)
ProgressBar1.Value = Text2.Text / 1024
DoEvents
Loop
Close #1
Close #2
Frame1.Caption = "Update Progress - Done!"
ProgressBar1.Value = ProgressBar1.Max
End Sub
Last edited by Ogmius; Nov 12th, 2003 at 06:15 PM.
"I dont even see the code anymore... I just see Blonde, Brunette, Redhead..."
Can you attach your form with the code in it? (It wil make it easier to look at)
10 different ways to skin a cat and amazingly enough each and every one has the same result, the cat gets skinned! The same can be applied to code, so be nice and accept each others "preferences".
The first thing that catches my eye is that you are doing a byte by byte copy. Which is slow. You would be better off with copying chunks at a time.....
Also, you are aware that the code will only copy the first 100 bytes, right?
I put your code into a little project of my own.. It runs pretty good. I copied files back and forth. It seems to be very quick. The only slowness I saw was with copying over our network.. Wich is what I would expect. Is that what you were seing (Slowness over a network connection)?
Here is my project for you to check out.
Rudy
10 different ways to skin a cat and amazingly enough each and every one has the same result, the cat gets skinned! The same can be applied to code, so be nice and accept each others "preferences".
Originally posted by techgnome The first thing that catches my eye is that you are doing a byte by byte copy. Which is slow. You would be better off with copying chunks at a time.....
Also, you are aware that the code will only copy the first 100 bytes, right?
Why do you say it will only copy the 1st 100 bytes? I copied a 2.5 Meg file with his code and it worked fine..
Rudy
10 different ways to skin a cat and amazingly enough each and every one has the same result, the cat gets skinned! The same can be applied to code, so be nice and accept each others "preferences".
Originally posted by kleinma maybe im missing something?
VB Code:
FileCopy([i]source as string[/i], [i]destination as string[/i])
kleinma,
I don;t think you can do a progress bar with filecopy.. can you?
10 different ways to skin a cat and amazingly enough each and every one has the same result, the cat gets skinned! The same can be applied to code, so be nice and accept each others "preferences".
I believe you are correct, but I don;t think that would serve his purpose.. I know I have had to do something similar in the past so that I could have a progress bar located on my form instead of another dialog box...
10 different ways to skin a cat and amazingly enough each and every one has the same result, the cat gets skinned! The same can be applied to code, so be nice and accept each others "preferences".
techgnome - Thanks for that code, it worked really awsome, and was perfect, my application is going to be copying larger files, so I noticed with my 25mb test file it was taking up to 60 - 90 seconds... the other problem that I have is how come it takes so long to release the files and the application when its done copying the files? I've seen this take up to 45 seconds
Thanks again, all of you for your suggestions
"I dont even see the code anymore... I just see Blonde, Brunette, Redhead..."
the filecopy part works awsome, I just cant figure out why it takes the app so long to close the files (aprox 30 - 45 Seconds) during which the application is locked too
Any more suggestions?
"I dont even see the code anymore... I just see Blonde, Brunette, Redhead..."
Nope, no extra code at all, just what is within that command function, but maybe its the fact that its a 25 meg file thats the killer? Because I did notice that the "lag" is significantly lower with smaller files such as text files...
as a matter of fact, I even tried compiling the application just to see if that would make any difference, I counted 37 seconds between the time the progress bar filled up, and the time that the message saying that the copy was competed came up and the application was available to the system again
Last edited by Ogmius; Nov 12th, 2003 at 06:51 PM.
"I dont even see the code anymore... I just see Blonde, Brunette, Redhead..."
I considered that too.. thats why I tried a 43 mb zip file and it took a total of maybe 20 seconds start to finish. No 30 second hang on the end. This must have something to do with your system or possibly the file you are copying is corrupted or something I dunno, without seeing it happen hard to say for sure
Originally posted by Ogmius Update, I even tried copying the application and zip file to another computer and even that didnt work
I dont know what else to do at this point this makes no sense at all
Ogmius,
I ran your code (See my attachment above for the project I put together with your code) and don't see the problem either.. But do this, add a text box to your form. In your code after everyline add this text1.text = now & vbnewline Run it. Look at the printout, then slowly remove the text1.text = now & vbnewline from various locations that you can see is not hanging. Eventually you will come to a point that you see exactly where you are hanging. That will help..
I know it seems like a lot, but I do this a lot when I get stuck oin something.. It really helps..
Also,
You might want to add some DoEvents around your code..
Let us know what happens..
Rudy
Last edited by RudyL; Nov 14th, 2003 at 12:11 PM.
10 different ways to skin a cat and amazingly enough each and every one has the same result, the cat gets skinned! The same can be applied to code, so be nice and accept each others "preferences".
In form1 just go into the code and change the source and destination files for the copy routine... everything else should just work fine.
Kleinma,
Nice job.. That runs nice..
Ogmius, I see your point now. It seems that the bigger the file the more the delay.. I think it is how you are copyiung the bytes.. If you were to read it all into memory first then copy it you might get rid of your delay. I think the problem is that everytime you copy a chunk windows is "re-alocating" memory for is and that is delaying the process, plus when it is done it now has all this memory to release.. A lot more than if you were to just copy the whole thing into memory first..
I will try to work up an example soon..
Rudy
10 different ways to skin a cat and amazingly enough each and every one has the same result, the cat gets skinned! The same can be applied to code, so be nice and accept each others "preferences".