Results 1 to 21 of 21

Thread: File Copy w/ Progress bar - Why so Slow??? - ALMOST RESOLVED

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2003
    Location
    Manchester, CT
    Posts
    317

    Question 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:
    1. Private Sub Command1_Click()
    2. Dim MyBytesa As Byte
    3. Dim MyBytesb As Byte
    4. Dim counter As Integer
    5.  
    6. Source = "C:\test.zip"
    7. Dest = "c:\testfolder\test.zip"
    8.  
    9. Open Source For Binary As #1
    10. Open Dest For Binary As #2
    11.    
    12. ProgressBar1.Max = FileLen(Source) / 1024
    13.  
    14. Text1.Text = FileLen(Source)
    15.  
    16. Do Until EOF(1)
    17.     counter = 0
    18.     MyBytesa = Empty
    19.     MyBytesb = Empty
    20.     Do Until (EOF(1)) Or (counter = 100)
    21.         Get #1, , MyBytesa
    22.         Put #2, , MyBytesa
    23.         counter = counter + 1
    24.     Loop
    25.     Text2.Text = FileLen(Dest)
    26.     ProgressBar1.Value = Text2.Text / 1024
    27.     DoEvents
    28. Loop
    29.  
    30. Close #1
    31. Close #2
    32. Frame1.Caption = "Update Progress - Done!"
    33. ProgressBar1.Value = ProgressBar1.Max
    34.  
    35. 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..."

  2. #2
    Frenzied Member RudyL's Avatar
    Join Date
    Mar 2001
    Location
    Chicago
    Posts
    1,519
    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".

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    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?
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim MyBytesa() As Byte
    3. Dim FileSize As Long
    4.  
    5. Source = "C:\test.zip"
    6. Dest = "c:\testfolder\test.zip"
    7.  
    8. Open Source For Binary As #1
    9. Open Dest For Binary As #2
    10.    
    11. ProgressBar1.Min = 0
    12. ProgressBar1.Max = (FileLen(Source) \ 1024) + 1
    13. ProgressBar1.Value = 0
    14.  
    15. FileSize = FileLen(Source)
    16. Text1.Text = FileSize
    17.  
    18. Do Until EOF(1)
    19.     If FileSize >= 1024 Then
    20.         ReDim MyBytesa(1024)
    21.     Else
    22.         ReDim MyBytesa(filezise)
    23.     End If
    24.    
    25.     Get #1, , MyBytesa
    26.     Put #2, , MyBytesa
    27.     DoEvents
    28.     Text2.Text = Val(Text1.Text - FileSize)
    29.     ProgressBar1.Value = ProgressBar1.Value + 1
    30.     DoEvents
    31.  
    32. Loop
    33.  
    34. Close #1
    35. Close #2
    36. Frame1.Caption = "Update Progress - Done!"
    37. ProgressBar1.Value = ProgressBar1.Max
    38.  
    39. End Sub


    TG
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4
    Frenzied Member RudyL's Avatar
    Join Date
    Mar 2001
    Location
    Chicago
    Posts
    1,519
    OK,

    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
    Attached Files Attached Files
    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".

  5. #5
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    maybe im missing something?

    VB Code:
    1. FileCopy([i]source as string[/i], [i]destination as string[/i])

  6. #6
    Frenzied Member RudyL's Avatar
    Join Date
    Mar 2001
    Location
    Chicago
    Posts
    1,519
    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".

  7. #7
    Frenzied Member RudyL's Avatar
    Join Date
    Mar 2001
    Location
    Chicago
    Posts
    1,519
    Originally posted by kleinma
    maybe im missing something?

    VB Code:
    1. 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".

  8. #8
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    Originally posted by RudyL
    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
    Wasn't unitl I was combing through it the second time that I say what was going on... .a loop inside a loop.


    TG
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  9. #9
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    Originally posted by RudyL
    kleinma,

    I don;t think you can do a progress bar with filecopy.. can you?
    maybe not with the VB file copy function.. but I know there is a way to envoke the windows file copy dialog and copy the files that way...

  10. #10
    Frenzied Member RudyL's Avatar
    Join Date
    Mar 2001
    Location
    Chicago
    Posts
    1,519
    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".

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2003
    Location
    Manchester, CT
    Posts
    317
    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..."

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2003
    Location
    Manchester, CT
    Posts
    317
    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..."

  13. #13
    Fanatic Member
    Join Date
    Sep 2002
    Location
    Lexington, SC
    Posts
    586
    I just set this up in my own application and I'm not seeing this delay after copying is done that you speak of.

    As soon as the progress bar is at the end and it says update complete.. tahts it.. I dont have any hang.

    You dont have any other code executing other than this do you?

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2003
    Location
    Manchester, CT
    Posts
    317
    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..."

  15. #15
    Fanatic Member
    Join Date
    Sep 2002
    Location
    Lexington, SC
    Posts
    586
    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

  16. #16

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2003
    Location
    Manchester, CT
    Posts
    317
    Argh! I dont get it, if I copy it in windows it works fine, but if I do it with the application i still get that lag!

    It just doesnt make sense

    are you closing the files when your done w/ the copy? because that is the part that seems to make everything "lag"



    FYI im doing all this on a P3 933 w/ 128mb RAM running windows 2000, that should definately be enough system to handle a file copy
    Last edited by Ogmius; Nov 13th, 2003 at 09:46 AM.
    "I dont even see the code anymore... I just see Blonde, Brunette, Redhead..."

  17. #17

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2003
    Location
    Manchester, CT
    Posts
    317
    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
    "I dont even see the code anymore... I just see Blonde, Brunette, Redhead..."

  18. #18
    Frenzied Member RudyL's Avatar
    Join Date
    Mar 2001
    Location
    Chicago
    Posts
    1,519
    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".

  19. #19
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    try using this?

    It may prove to work better for you....

    In form1 just go into the code and change the source and destination files for the copy routine... everything else should just work fine.
    Attached Files Attached Files

  20. #20
    Frenzied Member RudyL's Avatar
    Join Date
    Mar 2001
    Location
    Chicago
    Posts
    1,519
    Originally posted by kleinma
    try using this?

    It may prove to work better for you....

    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".

  21. #21

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2003
    Location
    Manchester, CT
    Posts
    317
    RudyL

    Any progress on that sample? I am not quite sure how to read the entire file into memory
    "I dont even see the code anymore... I just see Blonde, Brunette, Redhead..."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width