Can I use Awesomeium within a web application?

前端 未结 2 1081
独厮守ぢ
独厮守ぢ 2020-12-19 20:56

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

相关标签:
2条回答
  • 2020-12-19 21:16

    probably you need to call the webview.invoke or webview.begininvoke and you are going to need to create a delegate to access the webview that was created before the webcore.initialize in another thread, I would use a singleton pattern to use the same webview instance.

    0 讨论(0)
  • 2020-12-19 21:32

    Short answer: yes, you can.

    BUT according to the WebCore documentation:

    Note that Awesomium and Awesomium.NET are not thread-safe. All API members should be called from the thread that initialized the WebCore (see Initialize(WebConfig)) or created the first WebView, WebSession or technology specific WebControl.

    Also look at the Exceptions section of WebCore.Update() method description:

    System.AccessViolationException - You attempted to access the member from a thread other than thread where WebCore was created.

    Thus considering that every request in web application is generally processed in different thread, AccessViolationException is a documented feature.

    Therefore your task here is to guarantee that all Awesomium calls will be processed in a special dedicated thread. The thread should live on application level and its access has to be shared between requests. Technically, you need to write a kind of Message Loop or Synchronization Context where you will be able to push your delegate, Action or Func with Awesomium code to provide its execution only in this thread.

    0 讨论(0)
提交回复
热议问题