如何启动列表框中的所有文件
本文关键字:文件 列表 何启动 启动 | 更新日期: 2023-09-27 18:09:00
我还在学习c#,我需要一些帮助。我有一个列表框,其中包括所有要安排的文件,我使用DateTimePicker和DateTime。问题是程序只启动第一个选中的项目,而不启动其余的项目。我如何确定项目的优先级,使顶部开始,一直到退出,并继续到第二个文件?该程序是修改后的WPF应用程序。
Startupinfo = Listbox
代码如下:
Dictionary<string, string> startupinfoDict = new Dictionary<string, string>();
private bool startjob() //DateTime checking for DateValue and start's if correct value.
{
DateTime? start = DateTimePicker1.Value;
DateTime? end = DateTimePicker2.Value;
DateTime now = DateTime.Now;
if (start == null || end == null)
{
Xceed.Wpf.Toolkit.MessageBox.Show("one of the pickers is empty");
}
else if (now >= start.Value && now <= end.Value)
{
if (startupinfo.SelectedItem != null)
{
string s = startupinfo.SelectedItem.ToString();
if (startupinfoDict.ContainsKey(s))
{
Process process = Process.Start(startupinfoDict[s]);
process.WaitForExit();
while (!process.HasExited)
Thread.Sleep(500);
Xceed.Wpf.Toolkit.MessageBox.Show("It works woho");
}
}
return true;
}
return false;
}
尝试替换
if (startupinfo.SelectedItem != null)
{
string s = startupinfo.SelectedItem.ToString();
if (startupinfoDict.ContainsKey(s))
{
Process process = Process.Start(startupinfoDict[s]);
process.WaitForExit();
while (!process.HasExited)
Thread.Sleep(500);
Xceed.Wpf.Toolkit.MessageBox.Show("It works woho");
}
}
和像
这样的循环foreach (var selected in startupinfo.SelectedItems)
{
string s = selected.ToString();
if (startupinfoDict.ContainsKey(s))
{
Process process = Process.Start(startupinfoDict[s]);
process.WaitForExit();
while (!process.HasExited)
Thread.Sleep(500);
Xceed.Wpf.Toolkit.MessageBox.Show("It works woho");
}
}