Текущий SynchronizationContext нельзя использовать в качестве TaskScheduler. из CEFsharp EvaluateScriptAsync

Я пытаюсь асинхронно выполнить некоторый код JS в браузере CEF через CEFSharp. Мой код выглядит так;

debugForm = new CEFdebugger();
debugForm.browser.LoadingStateChanged += new EventHandler<CefSharp.LoadingStateChangedEventArgs>(webBrowser_LoadingStateChanged);
...
debugForm.browser.Load("local://wwwpub/index.html");
debugForm.Show();
...

void webBrowser_LoadingStateChanged(object sender, CefSharp.LoadingStateChangedEventArgs e)
{
    if (!e.IsLoading)
    {
            var task = debugForm.browser.EvaluateScriptAsync("1+1");
            task.ContinueWith(response =>
            {
...
            }, TaskScheduler.FromCurrentSynchronizationContext());
        }
    }

}

Линия;

task.ContinueWith(response =>

бросает

System.InvalidOperationException was unhandled
HResult=-2146233079
Message=The current SynchronizationContext may not be used as a TaskScheduler.
Source=mscorlib
StackTrace:
   at System.Threading.Tasks.SynchronizationContextTaskScheduler..ctor()
   at System.Threading.Tasks.TaskScheduler.FromCurrentSynchronizationContext()
   at KeyHandler.Interpreter.webBrowser_LoadingStateChanged(Object sender, LoadingStateChangedEventArgs e) in D:\development\Cubist\software\IoTkeys\IoTkeys\KeyHandler\Interpreter.cs:line 120
   at CefSharp.WinForms.ChromiumWebBrowser.CefSharp.Internals.IWebBrowserInternal.SetLoadingStateChange(LoadingStateChangedEventArgs args)
   at CefSharp.Internals.ClientAdapter.OnLoadingStateChange(ClientAdapter* , CefRefPtr<CefBrowser>* browser, Boolean isLoading, Boolean canGoBack, Boolean canGoForward)

Как решить эту проблему?


person P Hemans    schedule 11.12.2015    source источник


Ответы (1)


Проблема решилась заменой

task.ContinueWith(response =>
{
    ...
}, TaskScheduler.FromCurrentSynchronizationContext());

с этим

task.ContinueWith(response =>
{
    ...
});
person P Hemans    schedule 11.12.2015