我还在学习C#,我需要一些帮助。我有一个包含所有要安排的文件的列表框,我使用DateTimePicker和DateTime。问题是程序只启动第一个选定的项目,而不是其他项目。我如何确定项目的优先级,以便顶部首先启动,继续直到退出并继续第二个文件?该程序是一个改进的WPF应用程序。
Startupinfo =列表框
这是代码:
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;
}
答案 0 :(得分:1)
尝试替换
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");
}
}