Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 我可以在web应用程序中使用Awesomeum吗?_C#_Asp.net_Awesomium - Fatal编程技术网

C# 我可以在web应用程序中使用Awesomeum吗?

C# 我可以在web应用程序中使用Awesomeum吗?,c#,asp.net,awesomium,C#,Asp.net,Awesomium,我试图呈现一个html代码,将其导出到图像中,然后使用该图像将其放入pdf文档中。我在asp.net/C#web应用程序中完成了所有工作。我遇到的问题是,当我不止一次这样做时,会出现以下错误: 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.

我试图呈现一个html代码,将其导出到图像中,然后使用该图像将其放入pdf文档中。我在asp.net/C#web应用程序中完成了所有工作。我遇到的问题是,当我不止一次这样做时,会出现以下错误:

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,所以我把它放在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.
你知道我该怎么做吗


谢谢

简短回答:可以

但根据该报告:

请注意,Awesomium和Awesomium.NET不是线程安全的。所有API 应该从初始化WebCore的线程调用成员 (请参见初始化(WebConfig))或创建第一个WebView WebSession 或特定于技术的网络控制

另请查看以下内容的
例外部分:

-您试图访问 来自创建WebCore的线程以外的线程的成员

因此,考虑到web应用程序中的每个请求通常在不同的线程中处理,
AccessViolationException
是一个文档化的特性


因此,您在这里的任务是保证所有Awesomium调用都将在一个特殊的专用线程中处理。线程应该位于应用程序级别,其访问权限必须在请求之间共享。从技术上讲,您需要编写一种消息循环或同步上下文,以便能够推送您的
委托
Action
Func
使用一个特定的代码,以仅在此线程中提供其执行。

可能需要调用webview.invoke或webview.begininvoke,并且需要创建一个委托来访问在另一个线程中webcore.initialize之前创建的webview,我将使用单例模式来使用相同的webview实例。

根据您所描述的
WebCore.Initialize
应该放在
应用程序\u Start
WebCore.Shutdown
应该放在
全局.asax的
应用程序\u End
中。我这样做了,它给了我第二个错误:尝试读取或写入受保护的内存。这通常表示其他内存已损坏。当前线程当前未运行代码或无法获取调用堆栈。您可以提供一个示例吗?