Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- p = Launch("second");
- p.StandardOutput.ReadToEnd();
- p.WaitForExit();
- using System;
- using System.Diagnostics;
- using System.IO;
- using System.Runtime.InteropServices;
- namespace threadsubproc
- {
- class Program
- {
- static void Main(string[] args)
- {
- int ini = Environment.TickCount;
- string name = "first";
- try
- {
- if (args.Length == 1)
- {
- name = args[0];
- }
- Process p = null;
- switch (name)
- {
- case "first":
- p = Launch("second");
- p.StandardOutput.ReadToEnd();
- p.WaitForExit();
- return;
- case "second":
- Launch("third");
- return;
- case "third":
- System.Threading.Thread.Sleep(15000);
- return;
- }
- }
- catch (Exception e)
- {
- File.AppendAllText(name, e.Message + " " + e.StackTrace);
- }
- finally
- {
- File.AppendAllText(name, string.Format(
- "{0} - {1} finished. {2} ms", DateTime.Now, name, Environment.TickCount - ini));
- }
- }
- static Process Launch(string arg)
- {
- Process p = new Process();
- p.StartInfo.UseShellExecute = false;
- p.StartInfo.FileName = "threadsubproc";
- p.StartInfo.Arguments = arg;
- p.StartInfo.RedirectStandardOutput = true;
- p.StartInfo.RedirectStandardInput = true;
- p.StartInfo.RedirectStandardError = true;
- p.StartInfo.CreateNoWindow = true;
- p.Start();
- return p;
- }
- }
- }
Add Comment
Please, Sign In to add comment