forked from Kazbek/Parallel-Programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
65 lines (55 loc) · 2.01 KB
/
Program.cs
File metadata and controls
65 lines (55 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System;
using System.Diagnostics;
using System.Threading;
namespace SimpleProcessExample
{
class Program
{
static int Main(string[] args)
{
if(args.Length == 0)
return MainProcess();
else
return SubProcess(args);
}
private static Process savedProcess;
static int MainProcess()
{
Console.WriteLine("This is Main Process!");
Console.WriteLine($"File: {Process.GetCurrentProcess().MainModule.ModuleName}");
Process process = new Process();
savedProcess = process;
process.StartInfo.FileName = Process.GetCurrentProcess().MainModule.ModuleName;
process.StartInfo.Arguments = "first second third 1 2 3";
process.StartInfo.CreateNoWindow = false;
process.StartInfo.UseShellExecute = true;
process.EnableRaisingEvents = true;
process.Exited += ProcessOnExited;
//process.StartInfo.RedirectStandardOutput = true;
//process.OutputDataReceived += ProcessOnOutputDataReceived;
process.Start();
Console.ReadKey();
return 0;
}
private static void ProcessOnOutputDataReceived(object sender, DataReceivedEventArgs e)
{
Console.WriteLine($"Process {((Process)sender).Id} send: {e.Data}");
}
private static void ProcessOnExited(object sender, EventArgs e)
{
Console.WriteLine($"Exited type:{sender.GetType().FullName}");
Console.WriteLine($"Same process:{sender == savedProcess}");
Console.WriteLine($"Same process:{savedProcess.ExitCode}");
}
static int SubProcess(string[] args)
{
Console.WriteLine("This is SUB Process!");
foreach (string arg in args)
{
Console.WriteLine($"Arg: {arg}");
}
Thread.Sleep(2000);
return 43534536;
}
}
}