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.
Re: Application is freezing while copying (DoEvents doesn't work) !!!
Originally Posted by freesix
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.
Originally Posted by freesix
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'.
Originally Posted by freesix
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...
Originally Posted by freesix
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.
Originally Posted by freesix
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 !!
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.
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 !!!
Re: Application is freezing while copying (DoEvents doesn't work) !!!
Originally Posted by freesix
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).
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.
Last edited by fafalone; May 20th, 2016 at 02:39 PM.
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).
Re: Application is freezing while copying (DoEvents doesn't work) !!!
Originally Posted by freesix
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 '%'.
Originally Posted by freesix
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.
Re: Application is freezing while copying (DoEvents doesn't work) !!!
Call the CreateDirectory(StrPtr(dstPath), ByVal 0&) function in the CopyFolderInNewThread. Notice, you can't select the destination folder with the browse dialog in this case.
Re: Application is freezing while copying (DoEvents doesn't work) !!!
Originally Posted by freesix
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):
Originally Posted by freesix
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).
Originally Posted by freesix
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
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...
Re: Application is freezing while copying (DoEvents doesn't work) !!!
Originally Posted by fafalone
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.
Originally Posted by fafalone
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).
Originally Posted by fafalone
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-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.
Re: Application is freezing while copying (DoEvents doesn't work) !!!
Originally Posted by freesix
Is it possible to add another destination path?
I mean to make it two.
Sorry, i don't understand exactly. You can create another thread as well. Just create a new instance of the form (or any object wit ICopyFolderNotify interface) and run new progress there.
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.
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.
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.