当我将Visual Studio 2010的配置从Debug更改为Release时,我遇到了非常奇怪的行为:
我有一个BackgroundWorker
:_bg
,在DoWork
中我有:
iswaiting = true;
_bg.ReportProgress(1, filePath);
while (iswaiting)
{
;
}
//My other part of code (EDIT: something do to with the `result` I get from the user.)
在
ProgressChanged
中,我有一个 MessageBox
,用户交互后,iswaiting
将被设置为 false,_bg
的 DoWork
程序将继续执行。 void _bg_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
//my other part of code........
result = Microsoft.Windows.Controls.MessageBox.Show("Question" ,"Title", MessageBoxButton.YesNoCancel, MessageBoxImage.Warning);
iswaiting=false;
log(iswaiting.toString());
}
当我在Visual Studio中运行它或以Debug模式构建它时,这些都非常有效,但当我将其构建到Release时,尽管我可以从日志中看到
iswaiting
已经被设置为false
,但我永远无法跳出while(iswaiting)
循环。
编辑: 欢迎更好的方法!
DoWork
的其余部分移动到ProgressChanged
或Completed
可能不是正确的解决方案。 - Servy