-1

我仍在学习 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;
}
4

1 回答 1

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");
  }
}
于 2013-04-14T16:26:22.087 回答