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

timeout

Glossary Item Box

Closes std::in and 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 _
) As Boolean
C# 
public bool WaitForExit( 
   TimeSpan timeout
)

Parameters

timeout

Example

Library/Library.Test/TestProcessRunner.cs

C#Copy Code
string tempfile = Path.GetTempFileName();
try
{
    ProcessRunner runner = new ProcessRunner("cmd.exe");

    runner.Start();
    runner.StandardInput.WriteLine("ECHO Hello > " + tempfile);
    runner.StandardInput.WriteLine("EXIT");

    Assert.IsTrue(runner.WaitForExit(TimeSpan.FromMinutes(1)));
    Assert.AreEqual(0, runner.ExitCode);

    string output = File.ReadAllText(tempfile).Trim();
    Assert.AreEqual("Hello", output);
}
finally
{ File.Delete(tempfile); }
VB.NETCopy Code
Dim tempfile As String = Path.GetTempFileName()
Try
    Dim runner As New ProcessRunner("cmd.exe")

    runner.Start()
    runner.StandardInput.WriteLine("ECHO Hello > " + tempfile)
    runner.StandardInput.WriteLine("EXIT")

    Assert.IsTrue(runner.WaitForExit(TimeSpan.FromMinutes(1)))
    Assert.AreEqual(0, runner.ExitCode)

    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