Can I use Awesomeium within a web application?

一个人想着一个人 提交于 2019-11-29 11:47:10

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!