Waiting for a process to finish

Hi experts,

I start a process using the following code;

Public pro As New System.Diagnostics.Process()
Public proMRDCL As Process

    Sub RunShellCommand()
        Try
            pro.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
            pro.StartInfo.FileName = strMYPATH & "QBExports\QBmrdclEX.stp"
            proMRDCL = System.Diagnostics.Process.Start(pro.StartInfo)
        Catch
        End Try
    End Sub

What I want to do is send a character return to the process and then wait for the process to finish before killing it and my program carrying on running.

Can this be done?

Cheers,

Tom
LVL 3
TommyTwoPintsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Éric MoreauSenior .Net ConsultantCommented:
If the Process is ending by itself, you can use WaitForExit. See details at http://www.utmag.com/wconnect/wc.dll?LevelExtreme~9,7,10,,176
TommyTwoPintsAuthor Commented:
Hi emoreau,

When i inserted the WaitForExit into my code, it freezes my pc at runtime.

Is there another way around this?

Cheers,

Tom
Éric MoreauSenior .Net ConsultantCommented:
Try my demo to see if it is working.
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

TommyTwoPintsAuthor Commented:
Hi Eric,

The demo works as it should but not how i want it.

I automatically open a program and run it. The amount of time the program takes to run is always going to be different  (Due to the amount of data and different machine speeds).

I want to be able to wait until the program stops running then close it and move the output files it creates into other folders.

Basically i need to know when the program has stopped running.

Cheers,

Tom
Éric MoreauSenior .Net ConsultantCommented:
I have no idea. Can this program raise a signal to say it has finish?
tpwellsCommented:
instead of WaitForExit

try

WaitForInputIdle

msdn states "Causes the Process component to wait for the associated process to enter an idle state"

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDiagnosticsProcessClassWaitForInputIdleTopic.asp

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.