private void ChannelSynthesis_Click(object sender, RoutedEventArgs e) { if (!WorkIng) { WorkIng = true; process = new Process(); process.StartInfo.FileName = $"{Environment.CurrentDirectory}/ChannelSynthesisByCPU.exe"; process.StartInfo.Arguments = $"\"{OutPutPath}/Photo\""; //process.StartInfo.UseShellExecute = false; //process.StartInfo.RedirectStandardOutput = true; //process.StartInfo.CreateNoWindow = true; Cancel.IsEnabled = true; OutPutBox.Text = ""; task = new Task(() => { this.OutPutBox.Dispatcher.Invoke(new Action(() => { OutPutBox.AppendText("Alpha通道与RGB通道合成程序已启动,请等待"); OutPutBox.ScrollToEnd(); })); process.Start(); while (!process.HasExited) { Thread.Sleep(100); } this.OutPutBox.Dispatcher.Invoke(new Action(() => { OutPutBox.Text = OutPutBox.Text + $"{Environment.NewLine}核心程序已退出"; OutPutBox.ScrollToEnd(); })); if (Directory.Exists($"{OutPutPath}/Photo/OutPut")) { Process.Start($"{OutPutPath}/Photo/OutPut"); } if (CanCel) { CanCel = false; } this.ChannelSynthesis.Dispatcher.Invoke(new Action(() => { ChannelSynthesis.IsEnabled = false; })); this.Cancel.Dispatcher.Invoke(new Action(() => { Cancel.IsEnabled = false; })); WorkIng = false; }); task.Start(); } else { MessageBox.Show("已有项目在运行,请等待"); } }
private void ResourcesRelease_Click(object sender, RoutedEventArgs e) { if (Directory.Exists(InPutPath) && !WorkIng) { WorkIng = true; process = new Process(); process.StartInfo.FileName = $"{Environment.CurrentDirectory}/ResourcesReleaseTool.exe"; process.StartInfo.Arguments = $"-t -i \"{InPutPath}\" -o \"{OutPutPath}\""; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.CreateNoWindow = true; //process.StartInfo.StandardOutputEncoding = Encoding.ASCII; process.Start(); Cancel.IsEnabled = true; OutPutBox.Text = ""; task = new Task(() => { while (!process.HasExited) { string buffer = process.StandardOutput.ReadLine(); this.OutPutBox.Dispatcher.Invoke(new Action(() => { OutPutBox.AppendText(buffer + Environment.NewLine); OutPutBox.ScrollToEnd(); })); } this.OutPutBox.Dispatcher.Invoke(new Action(() => { OutPutBox.AppendText($"{Environment.NewLine}核心程序已退出"); OutPutBox.ScrollToEnd(); })); if (Directory.Exists($"{OutPutPath}/Photo")) { Process.Start($"{OutPutPath}/Photo"); } if (CanCel) { CanCel = false; } else { this.ChannelSynthesis.Dispatcher.Invoke(new Action(() => { ChannelSynthesis.IsEnabled = true; })); } this.Cancel.Dispatcher.Invoke(new Action(() => { Cancel.IsEnabled = false; })); WorkIng = false; }); task.Start(); } else if (WorkIng) { MessageBox.Show("已有项目在运行,请等待"); } else { MessageBox.Show("源目录不正确"); } }