x
Main Site login Signup

WebView do not load page

Sorry for my bad english.

I want make site snapshot (offscreen).

I made this class

 public class SiteShoter
 {
     int _width;
     static Thread _awesomiumTask;
     static SynchronizationContext _awesomeContext;

     public SiteShoter(int width)
     {
         _width = width;
     }

     public static void Init()
     {
         if (_awesomiumTask == null)
         {
             _awesomiumTask = new Thread(new ThreadStart(() =>
             {
                 WebCore.Started += (s, e) =>
                 {
                     _awesomeContext = SynchronizationContext.Current;
                 };
                 WebCore.Run();
             }));
             _awesomiumTask.Start();
         }
     }

     public void CreateWebshot(Uri url,string destFileName)
     {
         if (_awesomeContext == null)
             return;
         _awesomeContext.Send(state =>
         {
             using (var view = WebCore.CreateWebView(_width, 100, WebViewType.Offscreen))
             {
                 view.Crashed += (o, ee) =>
                 {
                     Console.WriteLine(ee.Status);
                 };
                 view.LoadingFrameComplete += (s, ee) =>
                 {
                     if (!ee.IsMainFrame)
                         return;
                     
                     var surface = (BitmapSurface)view.Surface;
                     surface.Resized += (oo, eee) =>
                     {
                         surface.SaveToPNG(destFileName, true);
                         Console.WriteLine("COMPLETED!");
                     };
                     var x = view.ExecuteJavascriptWithResult("Math.max(document.body.scrollWidth, document.body.offsetWidth)").ToString();
                     var y = view.ExecuteJavascriptWithResult("Math.max(document.body.scrollHeight, document.body.offsetHeight)").ToString();
                     view.Resize(Convert.ToInt32(x), Convert.ToInt32(y));
                 };
                 view.Source = url;
             }
         }, null);
     }
 }

but when i call CreateWebshot, nothing happenes. When i wrote under view.Source = url; this code

 while(view.IsLoading){}

 Console.WriteLine("LOADED");

cycle is not ended

Version 1.7.5.1

When I tried to do everything in one thread, initializing WebCore it all happened

asked Jan 13 at 04:45 AM avatar image iRumba 0
more ▼
(comments are locked)
10|1100 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.