This repository has been archived by the owner on Jan 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
71 lines (64 loc) · 1.95 KB
/
Program.cs
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
66
67
68
69
70
71
namespace Asynger
{
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Diagnostics;
using System.IO;
class AsyncExecuter
{
public static void Execute(IEnumerable<string> ACommandLines)
{
var taskList = new List<Task<Process>>();
foreach (var commandLine in ACommandLines)
{
var task = new Task<Process>(
() =>
{
var idxFirstSpace = commandLine.IndexOf(' ');
if (idxFirstSpace > 0)
{
var info = new ProcessStartInfo();
info.FileName = commandLine.Substring(0, idxFirstSpace);
info.Arguments = commandLine.Substring(idxFirstSpace + 1);
info.WindowStyle = ProcessWindowStyle.Hidden;
return Process.Start(info);
}
else
{
return Process.Start(commandLine);
}
});
task.Start();
taskList.Add(task);
}
Task.WaitAll(taskList.ToArray());
foreach (var task in taskList)
{
task.Result.WaitForExit();
}
}
}
class Program
{
static void Main(string[] args)
{
if (args.Length >= 1)
{
try
{
var Lines = File.ReadLines(args[0]);
AsyncExecuter.Execute(Lines);
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
else
{
Console.WriteLine("Asynger.exe <file.txt>");
}
}
}
}