C# 当前SynchronizationContext不能用作TaskScheduler。从CEFsharp EvaluateScript异步

C# 当前SynchronizationContext不能用作TaskScheduler。从CEFsharp EvaluateScript异步,c#,cefsharp,C#,Cefsharp,我试图通过CEFSharp在CEF浏览器中异步执行一些JS代码。 我的代码看起来像 debugForm = new CEFdebugger(); debugForm.browser.LoadingStateChanged += new EventHandler<CefSharp.LoadingStateChangedEventArgs>(webBrowser_LoadingStateChanged); ... debugForm.browser.Load("local://wwwpu

我试图通过CEFSharp在CEF浏览器中异步执行一些JS代码。 我的代码看起来像

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());
        }
    }

}
投掷

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)
System.InvalidOperationException未处理
HResult=-2146233079
Message=当前SynchronizationContext不能用作TaskScheduler。
Source=mscorlib
堆栈跟踪:
在System.Threading.Tasks.SynchronizationContextTaskScheduler..ctor()上
在System.Threading.Tasks.TaskScheduler.FromCurrentSynchronizationContext()中
在D:\development\Cubist\software\IoTkeys\IoTkeys\KeyHandler\explorer.webBrowser\u加载状态更改(对象发送方,加载状态更改Deventargs e)中的KeyHandler.explorer.webBrowser\u加载状态更改(对象发送方,加载状态更改Deventargs e):第120行
在CefSharp.WinForms.ChromiumWebBrowser.CefSharp.internal.IWebBrowserInternal.SetLoadingStateChange(LoadingStateChangedEventArgs参数)中
在CefSharp.Internals.ClientAdapter.OnLoadingStateChange(ClientAdapter*、cefreftr*浏览器、布尔isLoading、布尔canGoBack、布尔canGoForward)

如何解决此问题?

通过更换

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

task.ContinueWith(response =>
{
    ...
});
task.ContinueWith(response =>
{
    ...
});