无法退出 C# webbrowser.documentcompleted
我必须执行多个步骤来更新一堆网上商店,并且由于每次更新都需要对商店的特定部分执行一些操作,因此这需要以编程方式完成。
网上商店在 foreach 循环中被调用,如下所示: webbrowser.navigate("UrlStart" + Shop "UrlEnd)
我的 webbrowser.documentcompleted 由函数处理: void WebBrowser1OnDocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
在这个函数中,我有一个 if-else 语句来检查我想要使用的当前 URL。一个开关,但是 URL 取决于当前商店,因此页面上的某些操作需要重新加载页面,因此在这种情况下,我有用于原始加载/重新加载的附加开关
结构 OnDocumentCompleted 。是这样的:
if(e.Url.Tostring() == "Page1"){
switch{
case1: //Do stuff)
case2:navigate to Page2 }}
else if(e.Url.Tostring() == "Page2"){
//Do more stuff
navigate to Page3
}
else if(e.Url.Tostring() == "Page3"){
switch{
case3: // Do stuff
case4: // Do stuff
case5: navigate to Page4
}}
else if(e.Url.Tostring() == "Page4"){
switch{
case6: // Do stuff
case7: return;}
所有这些步骤都有效,这意味着在各个页面上进行两次登录和多次按钮单击。 然而,一旦我进入第 7 步并完成最终重新加载,程序就会继续运行而不执行任何操作。 我尝试过各种break组合;返回;在多个地方,我能想到的都是,但是函数 WebBrowser1OnDocumentCompleted
没有退出,我不明白为什么。
I have to do multiple steps for updating a bunch of webshops, and since every update requires some actions on specfic parts of the shops, this is to be done programmatically.
The webshops get called in a foreach loop, like this: webbrowser.navigate("UrlStart" + Shop "UrlEnd)
My webbrowser.documentcompleted is handled by a function: void WebBrowser1OnDocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
Inside this function, I have an if-else statement for checking the current URL. I wanted to go with a switch, however the URL is dependent on the current shop, thus the if-else. Some of the actions on the pages require reloading the page, so in this cases I have additional switch stetements for original load/reload.
The structure inside OnDocumentCompleted is like this:
if(e.Url.Tostring() == "Page1"){
switch{
case1: //Do stuff)
case2:navigate to Page2 }}
else if(e.Url.Tostring() == "Page2"){
//Do more stuff
navigate to Page3
}
else if(e.Url.Tostring() == "Page3"){
switch{
case3: // Do stuff
case4: // Do stuff
case5: navigate to Page4
}}
else if(e.Url.Tostring() == "Page4"){
switch{
case6: // Do stuff
case7: return;}
All these steps work, meaning two logins and multiple button clicks on various pages.
However, once I'm on step 7 and the final reload is done, the program just keeps running without doing anything.
I've tried various combinations of break; return; in mutliple places, all I could think of, but the function WebBrowser1OnDocumentCompleted
is not exited, and I can't figure out why.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论