asp.net-mvc 函数求值需要所有线程运行 - MVC
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34288814/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The function evaluation requires all threads to run - MVC
提问by surGe
The following error is occuring when passing values from a model to a parameter inside an If Statement.
将值从模型传递到 If 语句中的参数时,会发生以下错误。
This is the code the issue is occurring, I'm pretty sure its not the ValidateUserPasswordmethod.
这是发生问题的代码,我很确定它不是ValidateUserPassword方法。
if (PSFNetSystem.ValidateUserPassword(model.Server, model.Username, model.Password) < 0)
{
ModelState.AddModelError("Password", "Failed to login");
return View(model);
}
Any help is appreciated, thanks.
任何帮助表示赞赏,谢谢。
回答by Patrick Nelson - MSFT
Short answer:You can click on the "thread" icon to the right to force the evaluation.
简短回答:您可以点击右侧的“线程”图标强制评估。
Long answer:When you evaluate a method in the debugger, the debugger/CLR sets the context of the current thread to the method being evaluated, sets a guard breakpoint, freezes all threads except the current thread, then continues the process. When the breakpoint is hit, the debugger restores the thread to its previous state and uses the return value to populate the window.
长答案:当您在调试器中评估方法时,调试器/CLR 将当前线程的上下文设置为正在评估的方法,设置保护断点,冻结除当前线程之外的所有线程,然后继续该过程。当断点被击中时,调试器将线程恢复到其先前的状态并使用返回值来填充窗口。
Because only one thread is running, it's possible to create deadlock situations if the evaluation thread takes a lock that's already held by another thread. If the CLR detects a possible deadlock it aborts the evaluation and the debugger ultimately shows that message.
因为只有一个线程在运行,所以如果评估线程获取另一个线程已经持有的锁,就可能产生死锁情况。如果 CLR 检测到可能的死锁,它会中止计算,调试器最终会显示该消息。
Clicking the button to allow all threads to run means that we don't freeze the other threads when retrying the evaluation. This will allow the evaluation to proceed, but has the disadvantage of breakpoints on other threads being ignored.
单击按钮以允许所有线程运行意味着我们在重试评估时不会冻结其他线程。这将允许评估继续进行,但具有忽略其他线程上的断点的缺点。
BTW, If you are writing code that you know will likely deadlock if it's evaluated, you can call Debugger.NotifyOfCrossThreadDependeny. This will cause the behavior you are seeing.
顺便说一句,如果您正在编写的代码如果被评估可能会死锁,您可以调用 Debugger.NotifyOfCrossThreadDependy。这将导致您看到的行为。
回答by Christian Nielsen
It is because it needs to run the code to show you the result in the debugger. You can press the icon at the right to evaulate it, or you can go to Options -> Debugging and turn off "Enable property evaluation or other implicit function calls".
这是因为它需要运行代码才能在调试器中显示结果。您可以按右侧的图标对其进行评估,也可以转到选项 -> 调试并关闭“启用属性评估或其他隐式函数调用”。


