private static void Main(string[] args) { File.Delete("Temp.txt"); Trace.Listeners.Add(new ConsoleTraceListener()); Trace.Listeners.Add(new TextWriterTraceListener("Temp.txt")); AppDomain.CurrentDomain.UnhandledException += (sender, e) => { Trace.TraceError(e.ExceptionObject.ToString()); Trace.Flush(); Process.Start("Temp.txt"); }; Trace.WriteLine("Starting with arguments: {0}".FormatInvariant(args.ToString(" ", v => "\"{0}\"".FormatInvariant(v)))); switch (args[0]) { case "ChildProcessKiller": { Type childProcessKillerType = Type.GetType(args[1], true); IChildProcessKiller killer = (IChildProcessKiller)Activator.CreateInstance(childProcessKillerType); int childProcessCount; if (args.Length > 3) { childProcessCount = int.Parse(args[3]); } else { childProcessCount = 1; } for (int i = 0; i < childProcessCount; i++) { killer.AddProcess(Process.Start(args[2])); } Console.ReadLine(); } break; } Trace.Flush(); }
/// <summary> /// Initializes a new instance of the <see cref="TaskProcessExecutor"/> class. /// </summary> /// <param name="executableFilePath">The path to the executable file to be started in separate process when a new task is started.</param> /// <param name="childProcessKiller">The child process killer that is responsible for killing task process on task processor exit or crash.</param> /// <exception cref="ArgumentNullException">Parameter <paramref name="executableFilePath"/> is null or empty string, or <paramref name="childProcessKiller"/> is null.</exception> public TaskProcessExecutor(string executableFilePath, IChildProcessKiller childProcessKiller) { Trace.WriteLine("ENTER: Constructing {0} ...".FormatInvariant(this.debugName)); if (string.IsNullOrWhiteSpace(executableFilePath)) { throw new ArgumentNullException("executableFilePath"); } if (childProcessKiller == null) { throw new ArgumentNullException("childProcessKiller"); } this.executableFilePath = executableFilePath; this.childProcessKiller = childProcessKiller; Trace.WriteLine("EXIT: {0} constructed.".FormatInvariant(this.debugName)); }