【发布时间】:2018-08-27 11:31:00
【问题描述】:
我正在为一个清理实用程序编写一个 windows 窗体应用程序,其中 windows 窗体应用程序将执行多个具有相同进程属性的批处理文件来清理计算机的各个部分,这是我目前所拥有的,
ProcessStartInfo[] infos = new ProcessStartInfo[]
{
new ProcessStartInfo(Environment.CurrentDirectory + @"example batch file 1"),
new ProcessStartInfo(Environment.CurrentDirectory + @"example batch file 2"),
};
然后我执行它们,
Process[] startedProcesses = StartProcesses(infos, true);
每个进程的属性都包含在其中,
public Process[] StartProcesses(ProcessStartInfo[] infos, bool waitForExit)
{
ArrayList processesBuffer = new ArrayList();
foreach (ProcessStartInfo info in infos)
{
Process process = Process.Start(info);
if (waitForExit)
{
process.StartInfo.UseShellExecute = true;
process.StartInfo.Verb = "runas";
process.WaitForExit();
}
}
}
问题是,我想使用 if 语句将新的批处理文件添加到列表中,因为我希望用户使用选中的列表框来控制执行哪些批处理文件,例如,
ProcessStartInfo[] infos = new ProcessStartInfo[]
{
if (checkedListBox1.GetItemCheckState(0) == CheckState.Checked)
{
new ProcessStartInfo(Environment.CurrentDirectory + @"example batch file 1"),
}
if (checkedListBox1.GetItemCheckState(1) == CheckState.Checked)
{
new ProcessStartInfo(Environment.CurrentDirectory + @"example batch file 2"),
}
};
但这不起作用...有没有办法解决这个问题?
亲切的问候,雅各布
【问题讨论】:
标签: c# windows winforms process checkedlistbox