CSharpTest.Net
AssemblyRunner Class
Members  Example  See Also  Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Processes Namespace : AssemblyRunner Class

Glossary Item Box

Create an AppDomain configured to run the .Net Assembly provided and marshalls Console input/output to and from the app domain when run. This allow a more performant execution of .Net command-line tools while keeping with *most* of the behavior of running out-of-process. Some serious side effects can occur when using Environment.* settings like CurrentDirectory and ExitCode since these are shared with the appdomain.

Syntax

Visual Basic (Declaration) 
Public Class AssemblyRunner 
   Implements IRunner 
C# 
public class AssemblyRunner : IRunner  

Example

Library/Library.Test/TestAssemblyRunner.cs

C#Copy Code
Environment.CurrentDirectory = Path.GetDirectoryName(FileUtils.FindFullPath("cmd.exe"));

using (AssemblyRunner runner = new AssemblyRunner(Exe))
{
    ManualResetEvent gotExit = new ManualResetEvent(false);
    runner.ProcessExited += delegate(Object o, ProcessExitedEventArgs e) { gotExit.Set(); };
    Assert.IsFalse(runner.IsRunning);
    runner.Kill(); // always safe to call

    runner.Start("-wait");
    Assert.IsTrue(runner.IsRunning);

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

    Assert.IsFalse(runner.WaitForExit(TimeSpan.FromSeconds(1), false));
    runner.Kill();
    Assert.IsFalse(runner.IsRunning);
    Assert.IsTrue(gotExit.WaitOne(30000, false));
}
VB.NETCopy Code
Environment.CurrentDirectory = Path.GetDirectoryName(FileUtils.FindFullPath("cmd.exe"))

Using runner As New AssemblyRunner(Exe)
    Dim gotExit As New ManualResetEvent(False)
    runner.ProcessExited += Function(o As [Object], e As ProcessExitedEventArgs) Do
        gotExit.[Set]()
    End Function
    Assert.IsFalse(runner.IsRunning)
    runner.Kill()
    ' always safe to call
    runner.Start("-wait")
    Assert.IsTrue(runner.IsRunning)

    Try
        'make sure we can't start twice.
        runner.Start()
        Assert.Fail()
    Catch generatedExceptionName As InvalidOperationException
    End Try

    Assert.IsFalse(runner.WaitForExit(TimeSpan.FromSeconds(1), False))
    runner.Kill()
    Assert.IsFalse(runner.IsRunning)
    Assert.IsTrue(gotExit.WaitOne(30000, False))
End Using

Inheritance Hierarchy

System.Object
   CSharpTest.Net.Processes.AssemblyRunner

Requirements

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

See Also

Generated with Document! X 2011 by Innovasys