Capturing webpage as image in c#, ensuring javascript rendered elements are visible

后端 未结 4 1604
南方客
南方客 2020-11-30 04:37

I am trying to capture the following page using standard c# .net code. I\'ve searched around for people\'s various methods, most of which involve instantiating a browser ob

4条回答
  •  孤城傲影
    2020-11-30 04:45

    Thread.Sleep will simply suspend the thread your web browser is running on - how do you expect it to render anything when it is suspended? :)

    Instead, you need to allow the thread to process work. You can achieve this with a combination of Thread.Sleep(0) and Application.DoEvents(), with something like the following:

    DateTime finish = DateTime.Now.AddSeconds(3);
    while (DateTime.Now < finish) {
        Application.DoEvents();
        Thread.Sleep(0);
    }
    

提交回复
热议问题