这段代码在控制台应用程序和WinForm应用程序中运行完美。为什么此代码在WinForms中运行,但不在ASP.NET中运行?
我想使用ASP.NET网站,数据不能使用httpwebrequest
被retreived在相同的逻辑。
请让我知道如何解决这个问题。有什么比我能做得更好的吗?我标出了导致问题的线路。
private void runBrowserThread()
{
var th = new Thread(() =>
{
var br = new WebBrowser();
br.DocumentCompleted += browser_DocumentCompletedNew;
br.Navigate("https://www.linkedin.com/uas/login");
Application.Run(); // ERROR ON THIS LINE
});
th.SetApartmentState(ApartmentState.STA);
th.Start();
}
void browser_DocumentCompletedNew(object sender,
WebBrowserDocumentCompletedEventArgs e)
{
var br = sender as WebBrowser;
if (br.Url == e.Url)
{
}
}
在此先感谢您。
Application.Run一般只Winforms中的应用程式。请参阅:http://stackoverflow.com/questions/3034084/what-application-run-does –
为什么你想要一个窗体控件在asp.net环境中工作? – deostroll
刮去一个网站,但它不是纯HTML,它加载脚本约30秒,然后数据显示,所以我用一个浏览器控件。当所有被加载时它进入documentcompletedevent,所以我可以得到结果。有没有其他方法?现在想在网站上在线运行相同的东西,因此需要帮助。 –