DateTime tThen = DateTime.Now;
do
{
Application.DoEvents();
} while (!cefGlueBrowserForm.Done || tThen.AddSeconds(15) > DateTime.Now);
string htmlSource = cefGlueBrowserForm.DocumentDomHtml;
propertyBag.GetResponse = () => new MemoryStream(Encoding.UTF8.GetBytes(htmlSource));
cefGlueBrowserForm.Dispose();
几个小时后,我排队了
while (!cefGlueBrowserForm.Done || tThen.AddSeconds(15) > DateTime.Now);
的例外情况
System.Windows.Forms 中发生了类型为"System.StackOverflowException"的未处理异常.dll
以下是错误的描述:http://msdn.microsoft.com/en-us/library/w6sxk224%28v=vs.90%29.aspx
确保没有无限循环或无限递归。
过多的方法调用通常表示非常深或无限的递归。
那我该怎么办?我需要等到 cefGlueBrowserForm 中的某些代码完成或达到时间。但是为什么然后错误,我有时间检查...
Application.DoEvents
是邪恶的,不要使用它。它可能会导致无法解释的效果 - 如StackOverflow。应避免 UI 线程中的繁忙等待。要修复它,请使用,例如,BackgroundWorker
.
来自 MSDN 文档
条件 OR 运算符 (||) 对其布尔操作数执行逻辑 OR。如果第一个操作数的计算结果为 true,则不计算第二个操作数。
如果第一个条件为真,则不会检查||
中的第二个条件。
该程序说明了这个概念
class Program
{
static void Main(string[] args)
{
Console.WriteLine( p() || q() ); //prints Return True from p , True
Console.WriteLine( q() || p() ); //prints Return False from q, Return true from p, True
}
static bool p()
{
Console.WriteLine("Return True");
return true;
}
static bool q()
{
Console.WriteLine("Return False");
return false;
}
}