CSharpTest.Net
WaitForExit(TimeSpan,Boolean) Method
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Processes Namespace > ProcessRunner Class > WaitForExit Method : WaitForExit(TimeSpan,Boolean) Method

timeout
closeStdInput

Glossary Item Box

Waits for the process to exit, returns false if the process did not exit in the time given

Syntax

Visual Basic (Declaration) 
Public Overloads Function WaitForExit( _
   ByVal timeout As TimeSpan, _
   ByVal closeStdInput As Boolean _
) As Boolean
C# 
public bool WaitForExit( 
   TimeSpan timeout,
   bool closeStdInput
)

Parameters

timeout
closeStdInput

Example

Library/Library.Test/TestProcessRunner.cs

C#Copy Code
string tempfile = Path.GetTempFileName();
try
{
    Environment.CurrentDirectory = Path.GetDirectoryName(FileUtils.FindFullPath("cmd.exe"));
    ProcessRunner runner = new ProcessRunner("cmd.exe");
    Assert.IsFalse(runner.IsRunning);
    runner.Kill(); // always safe to call

    runner.Start("/K", "ECHO Hello > " + tempfile);
    Assert.IsTrue(runner.IsRunning);

    try //make sure we can't start twice.
    {
        runner.Start("/C", "ECHO", "HELO");
        Assert.Fail();
    }
    catch (InvalidOperationException)
    { }

    Assert.IsFalse(runner.WaitForExit(TimeSpan.FromSeconds(1), false));
    runner.Kill();
    string output = File.ReadAllText(tempfile).Trim();
    Assert.AreEqual("Hello", output);
}
finally
{ File.Delete(tempfile); }
VB.NETCopy Code
Dim tempfile As String = Path.GetTempFileName()
Try
    Environment.CurrentDirectory = Path.GetDirectoryName(FileUtils.FindFullPath("cmd.exe"))
    Dim runner As New ProcessRunner("cmd.exe")
    Assert.IsFalse(runner.IsRunning)
    runner.Kill()
    ' always safe to call
    runner.Start("/K", "ECHO Hello > " + tempfile)
    Assert.IsTrue(runner.IsRunning)

    Try
        'make sure we can't start twice.
        runner.Start("/C", "ECHO", "HELO")
        Assert.Fail()
    Catch generatedExceptionName As InvalidOperationException
    End Try

    Assert.IsFalse(runner.WaitForExit(TimeSpan.FromSeconds(1), False))
    runner.Kill()
    Dim output As String = File.ReadAllText(tempfile).Trim()
    Assert.AreEqual("Hello", output)
Finally
    File.Delete(tempfile)
End Try

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys