如何使用网络浏览器浏览链接列表? [英] How to navigate in a list of links using webbrowser?

查看:86
本文介绍了如何使用网络浏览器浏览链接列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个URL列表,我需要浏览它们.如何确保每个URL都将调用DocumentCompleted事件?我已经尝试创建多个线程,也尝试使用单个线程,但是该应用程序仍未触发每个URL的事件DocumentCompleted.

I have a list of url and I need to navigate them. How can I make sure that every url will call the DocumentCompleted event ? I've already tried to create many threads and tried using a single thread too but the app is still not firing the event DocumentCompleted for each url.

有没有一种方法可以在URL列表中循环并使它们调用DocumentCompleted,直到线程调用下一个URL?

Is there a way to make a loop in a list of urls and make them call a DocumentCompleted until the thread calls the next url ?

推荐答案

要实现此目的, async/await 任务并行库可能会派上用场.它们允许使用熟悉的伪线性代码流来表示异步逻辑(处理多次导航的DocumentCompleted事件,一个接一个).

To implement this, async/await and Task Parallel Library may come in handy. They allow to have familiar, pseudo-linear code flow for what is an asynchronous logic (handling DocumentCompleted events for multiple navigations, one after another).

对于 WinForm应用程序此处 控制台应用程序此处 .

I answered a similar question for a WinForm app here and for a console app here.

如果您需要定位.NET 4.0但使用VS2012 +进行开发,则仍然可以使用async/await,Microsoft提供了 Microsoft.Bcl.Async 库.

If you need to target .NET 4.0 but develop with VS2012+ , you still can use async/await, Microsoft provides the Microsoft.Bcl.Async library for that.

如果该项目没有C#5.0,则可以使用yield,如此处所述..

If C# 5.0 is not available for this project, you can use yield, as described here.

这篇关于如何使用网络浏览器浏览链接列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆