我對C#很陌生,我正在使用修改後的WPF應用程序。 與我的程序的問題是,循環是無限的... 而(現在<結束)不會在結束時結束它仍然會繼續,直到您終止主進程。 該程序顯示電影和圖片,因此每次都有所不同。這意味着現在= now.AddSeconds不起作用。對?while(now <end)在結束時沒有結束,它仍然在無限循環中繼續?
STARTUPINFO =列表框
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)
{
while (now < end)
{
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);
}
}
foreach (var selected in listBox2.SelectedItems)
{
string s = selected.ToString();
if (listBox2Dict.ContainsKey(s))
{
Process process = Process.Start(listBox2Dict[s]);
process.WaitForExit();
while (!process.HasExited)
Thread.Sleep(500);
}
}
}
return true;
}
return false;
}
我應該使用: while(start
Sneakybastardd
while(DateTimePicker1.Value <= DateTimePicker2.Value) 也不起作用。 – Sneakybastardd
我會'Datetime.now
karthikr