|
-
Dec 16th, 2020, 04:13 AM
#1
Thread Starter
Junior Member
Data Copy Operation and Process excecution
Hi,
I would like to copy a folder (with all it's contents - files /folders /hidden files folders /empty directories etc.)
And need to use this newly copied data to start a process, ... but if the copying operation is not finished already, the next process will give error.
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
My.Computer.FileSystem.CopyDirectory("C:\CopyFileDemo", "D:\CopyFileDemo")
Process.Start("D:\CopyFileDemo\MyData\MyApp.exe")
End Sub
In other words, I am looking for a way to copy directory first
My.Computer.FileSystem.CopyDirectory("C:\CopyFileDemo", "D:\CopyFileDemo")
and once this task is finished, proceed with the next task:
Process.Start("D:\CopyFileDemo\MyData\MyApp.exe")
-
Dec 16th, 2020, 09:38 AM
#2
Re: Data Copy Operation and Process excecution
This is just a guess... CopyDirectory works synchronously, so it should be all finished by your process line. Try putting an application.DoEvents between the two lines.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Dec 17th, 2020, 02:44 AM
#3
Thread Starter
Junior Member
Re: Data Copy Operation and Process excecution
Hi Paul and thanks for reply.
Do you have an example of this concept?
-
Dec 17th, 2020, 03:04 AM
#4
Re: Data Copy Operation and Process excecution
When you post code in this forum, select your code block and click the # (code) button in the post editor window...
Code:
My.Computer.FileSystem.CopyDirectory("C:\CopyFileDemo", "D:\CopyFileDemo")
Application.DoEvents
Process.Start("D:\CopyFileDemo\MyData\MyApp.exe")
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Dec 17th, 2020, 03:15 AM
#5
Thread Starter
Junior Member
Re: Data Copy Operation and Process excecution
 Originally Posted by .paul.
When you post code in this forum, select your code block and click the # (code) button in the post editor window...
Code:
My.Computer.FileSystem.CopyDirectory("C:\CopyFileDemo", "D:\CopyFileDemo")
Application.DoEvents
Process.Start("D:\CopyFileDemo\MyData\MyApp.exe")
And with this approach (Application.DoEvents), the command after this line will process only if the previous is finished, correct?
-
Dec 17th, 2020, 03:31 AM
#6
Re: Data Copy Operation and Process excecution
The previous command is synchronous, meaning it should finish before continuing execution. As this is not happening, the DoEvents might help. It’s not something that is lightly recommended, but in these circumstances it might work...
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Dec 18th, 2020, 10:33 AM
#7
Re: Data Copy Operation and Process excecution
From the original question, I'm not clear whether there actually IS a problem. I would expect CopyDirectory to be synchronous, and .paul. says that it is, in which case, everything should copy over before the Process.Start line is reached. You don't say that this doesn't happen, only that it would be bad if it did happen. Is it not happening? And are you sure that's the right problem?
I'm not sure that DoEvents will help, in this case. DoEvents will pause to process any pending events, but it seems like what would happen in CopyDirectory might not be an event that DoEvents would have any impact on (such as file copying resulting in a modal messagebox). So, you could put it in there to give it a try, I'm just thinking it won't solve whatever problem you are having. If it does solve it, you'd probably want to study further, because you'd want to know WHY DoEvents fixed the problem, or else it may not have really been solved. If DoEvents doesn't solve it, then I think you should explain what you are seeing and how you decided that the files weren't all being copied over.
My usual boring signature: Nothing
 
-
Dec 18th, 2020, 10:49 AM
#8
Re: Data Copy Operation and Process excecution
From current .NET runtime source (FileSystem.vb source from .NET Runtime):
VB.NET Code:
' NOTE: Decision to create target directory is different for Shell and Framework call.
If showUI <> UIOptionInternal.NoUI AndAlso Environment.UserInteractive Then
ShellCopyOrMove(operation, FileOrDirectory.Directory, SourceDirectoryFullPath, TargetDirectoryFullPath, showUI, onUserCancel)
Else
' Otherwise, copy the directory using System.IO.
FxCopyOrMoveDirectory(operation, SourceDirectoryFullPath, TargetDirectoryFullPath, overwrite)
End If
According to use of showUI parameter, the copying is performed in two completely different ways. So it depends on method overloads and some other settings. ShellCopyOrMove uses SHFileOperation to perform the copy when UI is required and it is not clear how it is done (requires more analysis of involved Windows APIs).
FxCopyOrMoveDirectory method is just pure .NET code that can be used if the OP wants such implementation.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|