C# 而(现在<;结束)不';t在结束时间结束它仍然在无限循环中继续?
我对C#还是个新手,我正在使用一个经过修改的WPF应用程序。 我的程序的问题是循环是无限的。。。 虽然(现在<结束)不会在结束时间结束,但它仍然会继续,直到您终止主进程。 这个节目正在播放电影和图片,因此每次都不一样。这意味着now=now.AddSeconds不起作用。对吧? startupinfo=ListboxC# 而(现在<;结束)不';t在结束时间结束它仍然在无限循环中继续?,c#,wpf,windows,datetime,loops,C#,Wpf,Windows,Datetime,Loops,我对C#还是个新手,我正在使用一个经过修改的WPF应用程序。 我的程序的问题是循环是无限的。。。 虽然(现在
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;
}
private bool startjob()//DateTime检查DateValue和start的值是否正确。
{
DateTime?start=DateTimePicker1.Value;
DateTime?end=DateTimePicker2.Value;
DateTime now=DateTime.now;
如果(开始==null | |结束==null)
{
Xceed.Wpf.Toolkit.MessageBox.Show(“其中一个选择器为空”);
}
否则,如果(now>=start.Value&&now您永远不会费心在循环中重新计算“now”。您没有在循环中修改now
的值。它将始终将now
计算为True。因此,无限循环now
变量的值永远不会更改。您可以改为以这种方式循环:
while (DateTime.Now < end.Value)
while(DateTime.Now
当我使用该代码时,什么都不会发生。我应该使用:while(startDateTime.Now
,它显然返回Now的值。如果“当我使用该选项时,不会发生任何事情”那么你可能应该知道为什么,也许检查一下日期时间选择器中的值,对不起,我忘记写明显的end.Value
而不是end
。我应该使用:while(startDatetime.now
,然后看看它是否有效!非常感谢!你给了我很多时间!我应该使用:while(start