Question

I have a C# code which opens RDP - iexplore.exe of another server. Now I have to scroll down the web page and take its screen shot, but on each scroll the image takes time to load. So when I take a screen shot on each scroll, sometimes the unloaded image gets saved.
I tried to put in a 1sec lag before taking the screenshot, but it isn't a full proof solution. Is there any other way/event to check that the web-page/that portion has loaded?

Following is my code :

        IHTMLElement2 scroller = null;
        if (currentSnapshot.IsFullPage)
        {
            scroller = GetScrolledElement(dimensions);
        }

        if (scroller != null)
        {
            originalScrollPosition = scroller.scrollTop;    //here's where we started to begin with
            maxScrollPosition = Math.Max(scroller.clientHeight, scroller.scrollHeight); 

            scroller.scrollTop = 0; //start at the top
        }
        var screen = SnapshotHelper.CaptureArea(dimensions);
        images.Add(screen);
        Thread.Sleep(1000);                    
        Application.DoEvents();

Thanks

Was it helpful?

Solution 2

Thanks for your suggestions sir. I was able to resolve the same using :

        while (IEApp.Busy)
            {                   
                Thread.Sleep(1000);
                Application.DoEvents();
            }

OTHER TIPS

I am going to imagine for a moment, that there is some real and practical reason you need to do all of this over RDP, and say that it cannot really be done directly. That being said, you could transmit the results of a screenshot taken on the remote side in coordination with IE back to the RDP client using a Virtual Channel.

Client opens RDP --RDP--> Server which runs service listening for virtual channel
  1. Client sends request to render across virtual channel
  2. Server renders and returns image

That being said, this would be a really good time to mention Awesomium, which hosts the same renderer as Chrome via a C# interface.

You could also implement the actual capture using the built in WebBrowser control, which uses IE to render. This blog has a good demo of how to do so.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top