|
-
Apr 25th, 2013, 09:25 AM
#1
Thread Starter
Member
[RESOLVED]process.start and process.waitforexit
this is probably pretty simple but i'm not seeing it. i'm doing the following
Code:
Process.Start("C:\Program Files\7-Zip\7z", "x" & " " & G.StagingDirectory & " " & "-o" & G.StagingDirectory)
'goes through directory and deletes the .mdoc files after they have been extracted
Dim filecount As Integer = 0
For Each filename As String In IO.Directory.GetFiles(G.StagingDirectory, "*.mdoc")
IO.File.Delete(filename)
filecount = filecount + 1
Next
the problem is it deletes the files before they can be extracted. i tried to use system.threading.thread.sleep(lots o seconds)
how can i make the program wait for the process to finish?
as always any help is welcomed.
Last edited by bsanders; Apr 25th, 2013 at 10:04 AM.
-
Apr 25th, 2013, 10:06 AM
#2
Re: [RESOLVED]process.start and process.waitforexit
You've answered your own question: by calling Process.WaitForExit. As the name suggests, Process.Start just starts a new process. Your code will then carry on while that process executes. If you don't want your code to carry on until the process finishes executing then you call Process.WaitForExit. You need to call it on the Process object returned by Process.Start though. That might look like this:
Code:
Dim proc = Process.Start(fileName, arguments)
proc.WaitForExit()
or, more succinctly, like this:
Code:
Process.Start(fileName, arguments).WaitForExit()
Note that WaitForExit is a blocking call, which means that your UI, if you have one, will freeze. If you want to avoid that then handle the Exited event of the Process instead and put the rest of your code in the event handler.
-
Apr 25th, 2013, 10:29 AM
#3
Thread Starter
Member
Re: [RESOLVED]process.start and process.waitforexit
yeah, thank you! i had to re-work my proc start but now it's working perfectly.
i tried to change this to a resolved thread but i'm a n00b and i'm not seeing that anywhere.
-
Apr 25th, 2013, 11:29 AM
#4
Re: [RESOLVED]process.start and process.waitforexit
 Originally Posted by bsanders
i tried to change this to a resolved thread but i'm a n00b and i'm not seeing that anywhere.
At the top of this webpage, you should see thread tools with a down arrow to the right of it, click on that. At the bottom of that menu, you should see Mark Thread As Resolved.
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
|