CSharpTest.Net
WaitForExit(TimeSpan) Method
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Processes Namespace > ScriptRunner 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/TestScriptRunner.cs

C#Copy Code
using (ScriptRunner runner = new ScriptRunner(ScriptEngine.Language.CSharp, "class Program { static void Main() { System.Threading.Thread.Sleep(System.TimeSpan.FromHours(1)); } }"))
{
    ManualResetEvent mre = new ManualResetEvent(false);
    runner.ProcessExited += delegate(object o, ProcessExitedEventArgs e) { mre.Set(); };

    runner.Start();
    Assert.IsTrue(runner.IsRunning);

    Assert.IsFalse(runner.WaitForExit(TimeSpan.Zero));
    runner.Kill();
    
    Assert.IsTrue(mre.WaitOne(0, false));
    Assert.IsFalse(runner.IsRunning);
    Assert.IsTrue(runner.WaitForExit(TimeSpan.Zero));
    Assert.AreNotEqual(0, runner.ExitCode);
}
VB.NETCopy Code
Using runner As New ScriptRunner(ScriptEngine.Language.CSharp, "class Program { static void Main() { System.Threading.Thread.Sleep(System.TimeSpan.FromHours(1)); } }")
    Dim mre As New ManualResetEvent(False)
    runner.ProcessExited += Function(o As Object, e As ProcessExitedEventArgs) Do
        mre.[Set]()
    End Function

    runner.Start()
    Assert.IsTrue(runner.IsRunning)

    Assert.IsFalse(runner.WaitForExit(TimeSpan.Zero))
    runner.Kill()

    Assert.IsTrue(mre.WaitOne(0, False))
    Assert.IsFalse(runner.IsRunning)
    Assert.IsTrue(runner.WaitForExit(TimeSpan.Zero))
    Assert.AreNotEqual(0, runner.ExitCode)
End Using

Requirements

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

See Also

Generated with Document! X 2011 by Innovasys