J'ai une liste d'URL dans une boucle for, en chargeant une URL à la fois, mais l'événement FinishLoadingFrameEvent n'est appelé qu'une seule fois.L'événement FinishLoadingFrameEvent est appelé une fois lors du chargement de plusieurs URL
Mon code complet est comme ça
private List<string> urls = //fetch from db;
ManualResetEvent waitEvent = new ManualResetEvent(false);
BrowserView webView = new WPFBrowserView();
string path = //my local path;
public MainWindow()
{
InitializeComponent();
mainLayout.Children.Add((UIElement)webView.GetComponent());
webView.Browser.FinishLoadingFrameEvent += delegate (object sender, FinishLoadingEventArgs e)
{
System.Threading.Thread.Sleep(5000);
if (e.IsMainFrame)
{
DOMDocument document = e.Browser.GetDocument();
var html = document.DocumentElement.InnerHTML;
System.IO.File.WriteAllText(path, html);
waitEvent.Set();
}
};
foreach (var url in urls)
{
webView.Browser.LoadURL(url);
waitEvent.WaitOne();
waitEvent.Reset();
}
}
Suis-je manque quelque chose?
essayez de mettre le 'waitEvent.Reset();' après le 'waitEvent.WaitOne();' dans la boucle for – Izikon
@Izikon essayé déjà .. – mathew
Une question similaire a été posée ici: https: // stackoverflow .com/questions/45642333/dotnetbrowser-finishloadingframeevent-multiple-use/45669011 # 45669011 –