Guest User

Untitled

a guest
Feb 20th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. p = Launch("second");
  2. p.StandardOutput.ReadToEnd();
  3. p.WaitForExit();
  4.  
  5. using System;
  6. using System.Diagnostics;
  7. using System.IO;
  8. using System.Runtime.InteropServices;
  9.  
  10. namespace threadsubproc
  11. {
  12. class Program
  13. {
  14. static void Main(string[] args)
  15. {
  16. int ini = Environment.TickCount;
  17.  
  18. string name = "first";
  19.  
  20. try
  21. {
  22. if (args.Length == 1)
  23. {
  24. name = args[0];
  25. }
  26.  
  27. Process p = null;
  28.  
  29. switch (name)
  30. {
  31. case "first":
  32. p = Launch("second");
  33. p.StandardOutput.ReadToEnd();
  34. p.WaitForExit();
  35.  
  36. return;
  37. case "second":
  38. Launch("third");
  39. return;
  40. case "third":
  41. System.Threading.Thread.Sleep(15000);
  42. return;
  43. }
  44. }
  45. catch (Exception e)
  46. {
  47. File.AppendAllText(name, e.Message + " " + e.StackTrace);
  48. }
  49. finally
  50. {
  51. File.AppendAllText(name, string.Format(
  52. "{0} - {1} finished. {2} ms", DateTime.Now, name, Environment.TickCount - ini));
  53. }
  54. }
  55.  
  56. static Process Launch(string arg)
  57. {
  58. Process p = new Process();
  59. p.StartInfo.UseShellExecute = false;
  60. p.StartInfo.FileName = "threadsubproc";
  61. p.StartInfo.Arguments = arg;
  62.  
  63. p.StartInfo.RedirectStandardOutput = true;
  64. p.StartInfo.RedirectStandardInput = true;
  65. p.StartInfo.RedirectStandardError = true;
  66. p.StartInfo.CreateNoWindow = true;
  67.  
  68. p.Start();
  69.  
  70. return p;
  71. }
  72. }
  73. }
Add Comment
Please, Sign In to add comment