async public Task ExecuteBatch(string batch, ExplorerExecuteBatchCallback callback) { //Thread thread = new Thread(new ParameterizedThreadStart(CommandInterpreter.RunProcess)); //thread.Start(new CommandInterpregerArgs(batch, callback)); await CommandInterpreter.RunProcess(batch, callback); }
async static internal Task RunProcess(string batch, ExplorerExecuteBatchCallback callback) { string path = SystemVariables.MyApplicationConfigPath + @"\explorer\tmp"; DirectoryInfo di = new DirectoryInfo(path); if (!di.Exists) { di.Create(); } string filename = di.FullName + @"\bat_" + Guid.NewGuid().ToString("N") + ".bat"; StreamWriter sw = new StreamWriter(filename); String2DOS(sw.BaseStream, "echo off\n" + batch.ToString()); sw.Close(); Thread thread1 = new Thread(new ThreadStart(ReadProcessStandardOutput)); Thread thread2 = new Thread(new ThreadStart(ReadProccessStandardError)); _proc = new Process(); _proc.StartInfo.FileName = filename; _proc.StartInfo.CreateNoWindow = true; _proc.StartInfo.RedirectStandardError = true; _proc.StartInfo.RedirectStandardOutput = true; _proc.StartInfo.RedirectStandardInput = false; _proc.StartInfo.UseShellExecute = false; _proc.Start(); thread1.Start(); thread2.Start(); _proc.WaitForExit(); thread1.Abort(); thread2.Abort(); FileInfo fi = new FileInfo(filename); fi.Delete(); _proc = null; if (callback != null) { var task = callback.Invoke(); await task; } }
public void ExecuteBatch(string batch, ExplorerExecuteBatchCallback callback) { Thread thread = new Thread(new ParameterizedThreadStart(CommandInterpreter.RunProcess)); thread.Start(new CommandInterpregerArgs(batch, callback)); }
public CommandInterpregerArgs(string command, ExplorerExecuteBatchCallback callback) : this(command) { Callback = callback; }