Webbrowser: sequencing activites when no DocumentCompleted is fired by a link on hosted webpage

余生长醉 提交于 2019-12-06 05:24:43

I'm posting here the solution i've been able to find for this problem: I wrote an extension method for the HtmlElement type as follows:

public static bool WaitForAvailability(this HtmlElement tag, string id, HtmlDocument   documentToExtractFrom, long maxCycles)
{ 
    bool cond = true; long counter = 0; 
        while (cond) 
        { 
        Application.DoEvents(); 
        tag = documentToExtractFrom.GetElementById(id);
         if (tag != null) 
            cond = false;
         Thread.SpinWait(50000);
         counter++; 
        if (counter > maxCycles) 
            return false; 
        } 
    return true;
 }

This allows the required tag to be waited for up to the moment when it will be really available in the page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!