x
Main Site login Signup

Can I use Awesomeium within an asp.net web application?

I'm trying to render a html code to export it to an image and then use that image to put it in a pdf document. I'm doing all in an asp.net/C# web application. The problem I'm having is that when I do that more than one time it give me this error:

 You are attempting to re-initialize the WebCore. The WebCore must only be initialized once per process and must be shut down only when the process exits.

This is my code:

 WebCore.Initialize(new WebConfig(), false);
 using (WebView webView = WebCore.CreateWebView(pageWidth, pageHeight))
 {
     webView.LoadHTML(html);

     while (webView.IsLoading || !webView.IsDocumentReady)
             WebCore.Update();

     Thread.Sleep(1100);
     WebCore.Update();

     string fileName = Server.MapPath("result.png");
     BitmapSurface surface = (BitmapSurface)webView.Surface;
     surface.SaveToPNG(fileName, true);

     WebCore.Shutdown();
 }

I figure that I can't initialize the WebCore every time the web page render, so I put it in the Global.asax. After doing this, when I'm debugging, another error came up:

 Attempted to read or write protected memory. This is often an indication that other memory is corrupt. The current thread is not currently running code or the call stack could not be obtained.

Any ideas how can I do this?

Thanks

asked Oct 14, 2013 at 06:42 PM avatar image rtorres 15
more ▼
(comments are locked)
avatar image ayubm1986 Jan 20, 2014 at 10:55 AM

I am having the same issue, did you solve it?

10|1100 characters needed characters left

3 answers: sort voted first

We do not officially support web applications mainly because:

  1. Awesomium is not thread-safe.

  2. We cannot spawn the WebCore multiple times for the main process hosting the library. In order for Awesomium to work in a web context, the WebCore would need to somehow persist between pages.

There are several ways to overcome that second obstacle above, but none of them is currently officially supported.

answered Jan 21, 2014 at 10:13 PM avatar image Perikles C. Stephanidis ♦♦ 10.7k
more ▼
(comments are locked)
avatar image ayubm1986 Jan 25, 2014 at 11:02 PM

Will you make webcore threadsome some time?

10|1100 characters needed characters left

I'm using Awesomium in an IIS web application and it works fine, except for the occasional crash mentioned here. You do need to run the awesomium stuff in a dedicated thread though, a thread that you keep alive until you shut down the web application. You might want to configure your application pool so it does not recycle though, by setting the "Idle Timeout" and the recycling "Regular Time Interval" to zero.

answered Jan 27, 2014 at 09:56 AM avatar image mtanneryd 171
more ▼
(comments are locked)
avatar image ayubm1986 Jan 27, 2014 at 11:47 AM

Can you please give an example on how to run it in a dedicated thread and spawn new webview on different page loads?

10|1100 characters needed characters left

Is there any plans to support this? I just need to run up an off screen site, wait for it to finish loading and take a screenshot. Is there anyway to do this?

answered Jul 22, 2016 at 06:16 AM avatar image benappswiz 0
more ▼
(comments are locked)
10|1100 characters needed characters left
Your answer
toggle preview:

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