我试图呈现一个html代码,将其导出到图像,然后使用该图像将其放入一个pdf文档。我正在做一个asp.net/C# web应用程序。我遇到的问题是,当我做一个以上的时间把它给我这个错误:我可以在Web应用程序中使用Awesomeium吗?
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.
这是我的代码:
WebCore.Initialize(new WebConfig(), false);
using (WebView webView = WebCore.CreateWebView((pdfWidth - 80).ToString().ToInt() + 20, (pdfHeight/2).ToString().ToInt() + 20))
{
webView.LoadHTML(html);
while (webView.IsLoading || !webView.IsDocumentReady)
WebCore.Update();
Thread.Sleep(1100);
WebCore.Update();
string fileName = Server.MapPath("result." + DateTime.Now.Second.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Millisecond.ToString() + ".png");
BitmapSurface surface = (BitmapSurface)webView.Surface;
surface.SaveToPNG(fileName, true);
WebCore.Shutdown();
}
我想,我不能初始化每次WebCore呈现WebCore,所以我把它放在Global.asax中。这样做后,当我在调试时,出现了另一个错误:
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.
任何想法我该怎么做?
感谢
从你所描述的'WebCore.Initialize'应该在'Application_Start'中,'WebCore.Shutdown'应该放在'Global.asax'的'Application_End'中。 – Romoku
我这样做,它给了我第二个错误:试图读取或写入受保护的内存。这通常表明其他内存已损坏。当前线程当前不在运行代码或无法获取调用堆栈。 – robert00769