我在VS Community 2015的WebForm项目中有这个代码:
var th = new Thread(() => {
var wb = new WebBrowser();
wb.DocumentCompleted += wb_DocumentCompleted;
wb.AllowNavigation = true;
wb.Navigate("https://www.ovo.com.au/login");
Application.Run();
});
th.SetApartmentState(ApartmentState.STA);
th.Start();
这是DocumentCompleted处理程序,运行正常但我无法调试
private async void wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
WebBrowser wb = (WebBrowser)sender;
System.Diagnostics.Debug.WriteLine(wb.Url);
}
当我放置一个断点时,我在Watch窗口中看到了这个:
错误CS0103:当前上下文中不存在名称“wb”
编辑/解决方案
解决方案是启用“使用托管兼容模式”(在工具>选项>调试>常规)