dcsimg
Page 2 of 2 FirstFirst 12
Results 41 to 63 of 63

Thread: [RESOLVED] Application is freezing while copying (DoEvents doesn't work) !!!

  1. #41
    Frenzied Member
    Join Date
    Feb 2015
    Posts
    1,364

    Re: Application is freezing while copying (DoEvents doesn't work) !!!

    I have made new example of my multithreading module that allows copy folder in other thread.

    This project has the module modCopyInThread that has CopyFolderInNewThread function. You should pass as the Cancel parameter variable that allows cancel operation. When you set this variable to true copying will be canceled. As notifications you should use ICopyFolderNotify object (object that supports ICopyFolderNotify interface), this object will be received the notifications from thread. I decide to use APC queue for in-thread communication therefore you should ensure the alertable state for the caller thread. I used a timer with SleepEx function that allows to process the ACP queue. This example works both in the IDE and in the compiled form (in IDE it uses main thread for processing) and doesn't have any dependencies after compilation.
    Attached Files Attached Files

  2. #42

    Thread Starter
    Lively Member
    Join Date
    Jan 2015
    Posts
    125

    Re: Application is freezing while copying (DoEvents doesn't work) !!!

    Thanks The Trick.

  3. #43
    PowerPoster
    Join Date
    Jun 2013
    Posts
    4,427

    Re: Application is freezing while copying (DoEvents doesn't work) !!!

    Quote Originally Posted by freesix View Post
    It works PERFECT like I wanted it.
    Playing around Forms or Displaying a MsgBox while copying doesn't interfere/stop the copy operation.

    It's just few codes compared with the regular multi-threading method that requires a lot of codes. I like it !!!
    Glad it works for you - and that it makes less source in your own App necessary,
    is quite normal for any larger Helper-Lib.

    Quote Originally Posted by freesix View Post
    1. Why your multi-threading runs in IDE whereas the regular one or the one for user "The Trick" requires that you only compile in EXE???
    The RC5-threading-support is based on (compiled) ActiveX-Dlls - and those are
    usually "extern" to your Exe-Project.

    In this case, the external Dll is the vbRichClient5.dll itself - therefore you didn't have
    to code (and compile) your own Dll (with a Public Class in it, which then does the "threading-work").

    In the example I gave, the Class in question, which gets instantiated on its own, separate thread -> is 'cFSO'.

    Quote Originally Posted by freesix View Post
    2. What are these Four (False, False, False, False) means??
    I know that the First one if turned to "True" hide the Windows Progress Bar. and what about the others!
    You will have to look in the VB6-ObjectExplorer (for the Method-Name which is called: MultiFileCopy).

    Alternatively, when you look at the Code-extract from the Demo:
    Code:
    Private Sub Form_Click()
      If ThFSO.JobQueueCount > 0 Then MsgBox "a copy-operation is still in progress": Exit Sub
    
      Caption = "Copy-operation in progress..."
      ThFSO.CallAsync "MultiFileCopy", "C:\Code\", "E:\Backup\", False, False, False, False
    
    '  New_c.FSO.MultiFileCopy "C:\Code\", "E:\Backup\", False, False, False, False '<- that'd be the EarlyBound (but non-threaded) variant of the above call
    End Sub
    In case you comment-in the green line below (and the 3 lines on top of it out), you could
    perform the same call "non-threaded" - but with Intellisense, which will give you Parameter-hints...

    Quote Originally Posted by freesix View Post
    3. How do I cancel that copy operation from Vb 6???
    Aside from Cancelling or Closing the Progress-Dialogue (which then in turn cancels the Thread-Method) -
    that's not possible in that simpler Threading-Demo, which calls only a "pre-encapsulated Method of a pre-existing Class".
    But in case you compile the other code-snippet (the Chunk-based one from #33) into your own Dll-(Class),
    you'd be able to use this in a thread as well - and can then raise Progress-Events back into your Main-App,
    and also Cancelling of the Copy-Operations would be possible.

    Quote Originally Posted by freesix View Post
    4. I didn't see a real Documentations explaining all of these things!!
    In their web-site I only found a lot of vb 6 source code !!! Where's the doc !!
    The "lot of Sourcecode" on the WebSite is commented Tutorials, which explain most of the Classes *and* their usage (by example).
    Aside from that there's a wiki-page which takes shape: http://vbrichclientframework.wikia.com
    And DrUnicode kindly compiled *.chm-HelpFiles for it: http://cyberactivex.com/UnicodeTutor...m#vbRichClient

    Quote Originally Posted by freesix View Post
    I checked that vbRichClient5 project and I discovered a lot of other interested things like changing the command button style. but I'll get into that later.
    In the meantime there's (besides the larger Tutorials on vbRichClient.com) also quite a lot of nice Demos here in this Forum.

    The easiest way to find them all - is to use the [Google Custom Search]-TextField (centered at the top of this Forum-Site).

    Olaf
    Last edited by Schmidt; May 18th, 2016 at 01:44 PM.

  4. #44

    Thread Starter
    Lively Member
    Join Date
    Jan 2015
    Posts
    125

    Re: Application is freezing while copying (DoEvents doesn't work) !!!

    Hi The Trick,

    I wanted to add a label displaying the percentage of copy progress like ( 13 % ).

    How do I do that??

  5. #45

    Thread Starter
    Lively Member
    Join Date
    Jan 2015
    Posts
    125

    Re: Application is freezing while copying (DoEvents doesn't work) !!!

    @ Schmidt,

    I checked that "MultiFileCopy" method but haven't found it in the VB6-ObjectExplorer,
    The only thing I found is "FileCopy" method.


    But in case you compile the other code-snippet (the Chunk-based one from #33) into your own Dll-(Class),
    you'd be able to use this in a thread as well - and can then raise Progress-Events back into your Main-App,
    and also Cancelling of the Copy-Operations would be possible.
    Why not use the code-snippet from #28 instead of #33.

    Please walk me through the process step by step how to do that from #28 code snippet, 'cause I'd like to implement the below methods (the whole with Multi-thread)

    1. How to hide that Windows progress bar that displays when copy is in progress?

    2. How to add a vb 6 progress bar and a label displaying the percentage of the copy operation in the Form.

    3. How to add an Abort/Abandon method via a Command button in the Form

    5. How to add Pause and Resume method via a command button in the Form


    That's all I need to complete that Project please.

    ===

    Apologies, I did not know before that this project was yours, that's why I wrote
    ...In their web-site I only found a lot of vb 6 source code !!! Where's the doc !!
    I thought you just let us know about it.

    I openned the "Read Me" file and found "Olaf".

    You've done a fantastic job. Thanks for that !!!

    ===

    VB 6 is really the cockroach that NEVER die !!! REALLY !!!

  6. #46
    Frenzied Member
    Join Date
    Feb 2015
    Posts
    1,364

    Re: Application is freezing while copying (DoEvents doesn't work) !!!

    Quote Originally Posted by freesix View Post
    Hi The Trick,

    I wanted to add a label displaying the percentage of copy progress like ( 13 % ).

    How do I do that??
    The ICopyFolderNotify::CopyProgress callback method is called when data part has been written.
    TotalSize - the size of current file;
    NumberOfBytesTransfered - the number of written the bytes of the current file;
    RemainData - the size of remain data;
    TotalBytesCount - the total size of data;
    You can calculate the progress of all data as RemainData / TotalBytesCount and the progress of current file as NumberOfBytesTransfered / TotalSize. In the code that i attached the percents is already calculated (look at allProgress and curProgress variables).

  7. #47
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    2,351

    Re: Application is freezing while copying (DoEvents doesn't work) !!!

    The richclient example seems to use FSO, so you won't be able to customize the operation. If there's other calls that use other methods maybe something is possible, but only if already built in since closed-source can't be customized; here both richclient AND FSO being high-level black boxes.

    Copying manually like #33 would allow those options too; but if you're going that route you don't neccessarily need richclient since it's just a matter of opening the source and creating the destination with CreateFile, then using ReadFile/WriteFile; a good wrapper for that is a class module by dilettante; VB6 - Huge (>2GB) Text and Binary File I/O Classes. That would allow maximum responsiveness and complete control over pause/resume/cancel without multithreading or a DLL/TLB depend, at the expense of requiring a bit more effort. Although technically you'd still have to stick it in another thread if MsgBox holding up copying is really a deal-breaker; using the timer trick would probably result in a slow copy even though technically it would work (Timer events will fire even if a msgbox is being displayed; you could call the routine to copy the next block from there, but even a 1ms interval might be too slow depending on block size-- although possibly worth considering if slowing down is an acceptable tradeoff to avoid multithreading or closed-source depends).

    Although really it might be easier to just use a form that looks like a msgbox. That wouldn't hold up a copy.

  8. #48

    Thread Starter
    Lively Member
    Join Date
    Jan 2015
    Posts
    125

    Re: Application is freezing while copying (DoEvents doesn't work) !!!

    @ The Trick (sorry for the delay)

    I put below statements

    Label3.Caption = curProgress
    Label3.Caption = 'RemainData / TotalBytesCount
    and others you quoted above.

    but I still get some kind of "Floating numbers" displaying on the Label3.Caption when running the App.

    Can you help please.

  9. #49

    Thread Starter
    Lively Member
    Join Date
    Jan 2015
    Posts
    125

    Re: Application is freezing while copying (DoEvents doesn't work) !!!

    @ The Trick (sorry for the delay)

    I put below statements

    Label3.Caption = curProgress
    Label3.Caption = 'RemainData / TotalBytesCount
    and others you quoted above.

    but I still get some kind of "Floating numbers" displaying on the Label3.Caption when running the App.
    and when the copy operation is completed, the Label3 displays "1"


    In addition, I also wanted to re-create the Source Folder in the Destination location,
    I mean, I tried to copy a Folder named "SwSetup" that contains many others folders and files within.
    It copies very well all those folders and files within but it doesn't copy the Root Source Folder (SwSetup).

    How can I fix it??


    Can you please help for both concerns.

  10. #50
    Frenzied Member
    Join Date
    Feb 2015
    Posts
    1,364

    Re: Application is freezing while copying (DoEvents doesn't work) !!!

    Quote Originally Posted by freesix View Post
    I still get some kind of "Floating numbers" displaying on the Label3.Caption when running the App.
    and when the copy operation is completed, the Label3 displays "1"
    Because you should either multiple to 100 or use Format function with '%'.
    Quote Originally Posted by freesix View Post
    In addition, I also wanted to re-create the Source Folder in the Destination location,
    I mean, I tried to copy a Folder named "SwSetup" that contains many others folders and files within.
    It copies very well all those folders and files within but it doesn't copy the Root Source Folder (SwSetup).
    You can just create a folder before copying and copy all the subfolders to there. Of course you can change the function in order to it creates the folder by itself. Add the CreateDirectory function to there.

  11. #51

    Thread Starter
    Lively Member
    Join Date
    Jan 2015
    Posts
    125

    Re: Application is freezing while copying (DoEvents doesn't work) !!!

    Because you should either multiple to 100 or use Format function with '%'.
    How can I use Format "%" in a Label???

    It's not a DTPicker that I easily can Format ????

  12. #52

    Thread Starter
    Lively Member
    Join Date
    Jan 2015
    Posts
    125

    Re: Application is freezing while copying (DoEvents doesn't work) !!!

    @ fafalone.

    Thanks for your PRECIOUS ideas,

    I'm going to consider that too.


    But the problem is I don't have in-deep knowledge of Multi-threading.
    I'm scared of it !!!

    (In Delphi we merely used "TThread Class" to implement multi-thread but in VB6 I read a couple of books but I still don't understand it!!!


    The only thing I got is the basic concept (Theory) but Practically I'm even unable to write a small piece of codes to implement Multi-thread.
    Last edited by freesix; May 24th, 2016 at 12:34 PM.

  13. #53

  14. #54
    PowerPoster
    Join Date
    Jun 2013
    Posts
    4,427

    Re: Application is freezing while copying (DoEvents doesn't work) !!!

    Quote Originally Posted by freesix View Post
    I checked that "MultiFileCopy" method but haven't found it in the VB6-ObjectExplorer,
    The only thing I found is "FileCopy" method.
    If the project contains a reference to vbRichClient5, then you should be able to find
    the term MultiFileCopy when using the VB6-ObjectExplorer-SearchField (as shown below):



    Quote Originally Posted by freesix View Post
    Why not use the code-snippet from #28 instead of #33.
    If you need more control over the Cancelling-Option (not relying on any (Explorer-)Shell-Dialogues),
    then there's no other way, than to use the code-base of #33 (the low-level, chunkwise File-Copying).


    Quote Originally Posted by freesix View Post
    Please walk me through the process step by step how to do that from #28 code snippet, 'cause I'd like to implement the below methods (the whole with Multi-thread)

    1. How to hide that Windows progress bar that displays when copy is in progress?

    2. How to add a vb 6 progress bar and a label displaying the percentage of the copy operation in the Form.

    3. How to add an Abort/Abandon method via a Command button in the Form
    All that I've just wrapped up in an additional (third) example (AsyncFolderCopy) in the
    CodeBank-thread which covers the RC5-threading support...:
    http://www.vbforums.com/showthread.p...-ThreadHandler

    Quote Originally Posted by freesix View Post
    5. How to add Pause and Resume method via a command button in the Form
    You can add that with relative ease in the cCopyThread-class of the "AsyncFolderCopy-Demo" in
    the above linked Demo-Project (e.g. per raising an appropriate Cancel-Event, which hands over
    the current Source-FileNamePath into the Main-Thread).

    You could then use an additional Optional Parameter in the 'CopyFolderTo' routine, where you
    hand over that "FileNamePath_ToResumeFrom"-Parameter - then skipping over the CopyFile-routine
    until the right "Filename to resume from" came up in the enumeration...

    HTH

    Olaf

  15. #55
    PowerPoster
    Join Date
    Jun 2013
    Posts
    4,427

    Re: Application is freezing while copying (DoEvents doesn't work) !!!

    Quote Originally Posted by fafalone View Post
    The richclient example seems to use FSO, so you won't be able to customize the operation.
    The RichClient doesn't use the (Scripting-)FSO - it has its own cFSO-Class which contains
    a lot more than what the Scripting.FSO has to offer.

    As for "customizing" - the RC5-threading-Demo in #28 is asynchronously calling a single Method
    of the cFSO-class (which was instantiated on its own thread before): .MultiFileCopy ...
    Not much to "customize" there...

    The Example which shows a "customizable Folder-Copying" (per RC5-cFSO) was given in #33.

    Quote Originally Posted by fafalone View Post
    If there's other calls that use other methods maybe something is possible, but only if already built in since closed-source can't be customized...
    The RC5-cFSO-Class offers an "API-Interface" which contains enough encapsulations of LowLevel-APIs
    (as shown in #33 with the Stream-Handling and the SetFileAttributesEx-methods).

    Quote Originally Posted by fafalone View Post
    Copying manually like #33 would allow those options too; but if you're going that route you don't neccessarily need richclient since it's just a matter of opening the source and creating the destination with CreateFile, then using ReadFile/WriteFile...
    Of course one can use also Win32-APIs from user32- or kernel32.dll (BTW, also closed source) instead of the RC5-Stream-Classes -
    but it will result in significantly more code - and then the question remains, how stable all that is -
    and how to "run all that stuff on a thread".

    The threading-support of the RC5 can manage such tasks without much fuss and relatively small coding-efforts -
    as shown in the (now extended) Demo-Zip here:
    http://www.vbforums.com/showthread.p...-ThreadHandler

    The threading-Demos from Anatoli (The Trick) are not bad - but they require a higher skill-level
    (IMO) than the threading-implementations which are possible with the RC5...

    As always with helper-libraries, one needs to "weigh" the advantage of "less user-code" vs.
    "the necessity to ship an additional dependency".

    Olaf
    Last edited by Schmidt; May 24th, 2016 at 03:37 PM.

  16. #56

    Thread Starter
    Lively Member
    Join Date
    Jan 2015
    Posts
    125

    Re: Application is freezing while copying (DoEvents doesn't work) !!!

    @The Ttrick.

    I finaly did it using below statement.
    Label3.Caption = FormatPercent(allProgress, 0)
    and I obviously get exactly the percentage like (15%)


    Is it possible to add another destination path?
    I mean to make it two.

  17. #57

  18. #58

    Thread Starter
    Lively Member
    Join Date
    Jan 2015
    Posts
    125

    Re: Application is freezing while copying (DoEvents doesn't work) !!!

    Hi, I tried to Call the CreateDirectory(StrPtr(dstPath), ByVal 0&) as suggested but I'm still unable to accomplish that.

    Please can you help programatically?

  19. #59

    Thread Starter
    Lively Member
    Join Date
    Jan 2015
    Posts
    125

    Re: Application is freezing while copying (DoEvents doesn't work) !!!

    I finally solved it.


    Thanks SO MUCH to everyone !!!
    Last edited by freesix; Jun 9th, 2016 at 06:02 AM.

  20. #60
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,073

    Re: [RESOLVED] Application is freezing while copying (DoEvents doesn't work) !!!

    29 replies and not one solved your problem and then out of nowhere you post that you finally solved the problem without a clue on how you did it.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  21. #61

    Thread Starter
    Lively Member
    Join Date
    Jan 2015
    Posts
    125

    Re: [RESOLVED] Application is freezing while copying (DoEvents doesn't work) !!!

    Sorry, it's my mistake I wasn't explicit when I said in my previous post "I finally solved it."

    So, I meant I solved the last problem I encountered posted in code-snippet #58 regarding The Trick's project.

  22. #62

    Thread Starter
    Lively Member
    Join Date
    Jan 2015
    Posts
    125

    Re: [RESOLVED] Application is freezing while copying (DoEvents doesn't work) !!!

    Indeed, I've got 3 differents projects to build in VB 6, the most urgent is the one I'm working on now and
    according to the suggestions of many people here in this Forum, they advised me to use "Multi-Threading" regarding the reason I quoted in snippet "#38".

    And I also double checked in many VB 6 books, and found their suggestions OBVIOUS.

    Multi-threading is the solution ONLY FOR THIS PROJECT...
    but personally I don't have indeep knowledge of Multi-threading to start working on "Schmidt" or/and others code posted above even in #55.

    I can read books, understand theory but we all know I won't be able to build a real multi-threading App in a couple of weeks (That's the Truth).

    besides, I also runnning out of time, as it's not the ONLY module I have to do, they are many others I have to work on to finish this project.


    Like I said, I still have two other projects that will also need copy operation within,
    but with less requirements this time and I'm gonna use "Fafalone and Schmidt" code.


    I wanted to use "Schmidt" code too with its small DLL (vbRichClient5.dll) as it doesn't request much code and I can easily read it
    but I would need to spend more time learning it.


    Even The Trick code, I still have to do some change within, but not related to Multithreading this time, only the VB code,

    like : when you compile his project "TrickMultithreading_test7.zip" in EXE found in snippet in "#41",
    once you try to run that EXE, you got warning from the Antivirus considering it as a Threat/suspicious file due to the VB Script object "CreateObject("Shell.Application")" located in BrowseForFolderSource" function. (as I figured it out)

    and I have to change that function into the regular one

    Dim FileSystemObject As Object
    Set FileSystemObject = CreateObject("Scripting.FileSystemObject")

    Dim fso As New Scripting.FileSystemObject, dr As Scripting.Drive

    With udtBI
    'Set the owner window
    .hWndOwner = Me.hWnd
    'lstrcat appends the two strings and returns the memory address
    .lpszTitle = lstrcat("Select the folder to backup", "")
    'Return only if the user selected a directory
    .ulFlags = BIF_RETURNONLYFSDIRS
    End With

    'Show the 'Browse for folder' dialog
    lpIDList = SHBrowseForFolder(udtBI)
    If lpIDList Then
    sPath = String$(MAX_PATH, 0)
    'Get the path from the IDList
    SHGetPathFromIDList lpIDList, sPath
    'free the block of memory
    CoTaskMemFree lpIDList
    iNull = InStr(sPath, vbNullChar)
    If iNull Then
    sPath = Left$(sPath, iNull - 1)
    End If
    Else
    Exit Sub
    End If


    but I'm/We're still open and the thread too ...whether others are updating their codes, their can still post them.

    Again, Thanks to everybody

  23. #63

    Thread Starter
    Lively Member
    Join Date
    Jan 2015
    Posts
    125

    Re: [RESOLVED] Application is freezing while copying (DoEvents doesn't work) !!!

    Indeed, I've got 3 differents projects to build in VB 6, the most urgent is the one I'm working on now and
    according to the suggestions of many people here in this Forum, they advised me to use "Multi-Threading" regarding the reason I quoted in snippet "#38".

    And I also double checked in many VB 6 books, and found their suggestions OBVIOUS.

    Multi-threading is the solution ONLY FOR THIS PROJECT...
    but personally I don't have indeep knowledge of Multi-threading to start working on "Schmidt" or/and others code posted above even in #55.

    I can read books, understand theory but we all know I won't be able to build a real multi-threading App in a couple of weeks (That's the Truth).

    besides, I also runnning out of time, as it's not the ONLY module I have to do, they are many others I have to work on to finish this project.


    Like I said, I still have two other projects that will also need copy operation within,
    but with less requirements this time and I'm gonna use "Fafalone and Schmidt" code.


    I wanted to use "Schmidt" code too with its small DLL (vbRichClient5.dll) as it doesn't request much code and I can easily read it
    but I would need to spend more time learning it.


    Even The Trick code, I still have to do some change within, but not related to Multithreading this time, only the VB code,

    like : when you compile his project "TrickMultithreading_test7.zip" in EXE found in snippet in "#41",
    once you try to run that EXE, you got warning from the Antivirus considering it as a Threat/suspicious file due to the VB Script object "CreateObject("Shell.Application")" located in BrowseForFolderSource" function. (as I figured it out)

    and I have to change that function into the regular one

    Dim FileSystemObject As Object
    Set FileSystemObject = CreateObject("Scripting.FileSystemObject")

    Dim fso As New Scripting.FileSystemObject, dr As Scripting.Drive

    With udtBI
    'Set the owner window
    .hWndOwner = Me.hWnd
    'lstrcat appends the two strings and returns the memory address
    .lpszTitle = lstrcat("Select the folder to backup", "")
    'Return only if the user selected a directory
    .ulFlags = BIF_RETURNONLYFSDIRS
    End With

    'Show the 'Browse for folder' dialog
    lpIDList = SHBrowseForFolder(udtBI)
    If lpIDList Then
    sPath = String$(MAX_PATH, 0)
    'Get the path from the IDList
    SHGetPathFromIDList lpIDList, sPath
    'free the block of memory
    CoTaskMemFree lpIDList
    iNull = InStr(sPath, vbNullChar)
    If iNull Then
    sPath = Left$(sPath, iNull - 1)
    End If
    Else
    Exit Sub
    End If


    but I'm/We're still open and the thread too ...whether others are updating their codes, their can still post them.

    Again, Thanks to everybody

Page 2 of 2 FirstFirst 12

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width