我試圖呈現一個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