From 1def8a7937dce48e6f6264ae147cd63bdfd8c598 Mon Sep 17 00:00:00 2001 From: Alex Maitland Date: Sat, 10 Jun 2023 07:33:20 +1000 Subject: [PATCH] Upgrade to .Net 4.6.2 (#4482) * Upgrade minimum .Net version to 4.6.2 #4433 * Use TaskCreationOptions.RunContinuationsAsynchronously - Now that min version is .Net 4.6.2 we can use RunContinuationsAsynchronously - Remove some unused code --- .../CefSharp.BrowserSubprocess.Core.vcxproj | 6 +- .../CefSharp.BrowserSubprocess.csproj | 2 +- CefSharp.BrowserSubprocess/app.config | 2 +- .../CefSharp.Core.Runtime.vcxproj | 6 +- .../Internals/CefBrowserHostWrapper.cpp | 5 +- .../Internals/ClientAdapter.cpp | 2 +- CefSharp.Core/CefSharp.Core.csproj | 2 +- CefSharp.Core/DevTools/DevToolsClient.cs | 8 +- CefSharp.Core/WebBrowserExtensionsEx.cs | 10 +- CefSharp.OffScreen/CefSharp.OffScreen.csproj | 2 +- CefSharp.OffScreen/ChromiumWebBrowser.cs | 18 ++-- CefSharp.WinForms/CefSharp.WinForms.csproj | 2 +- CefSharp.Wpf/CefSharp.Wpf.csproj | 2 +- CefSharp.Wpf/ChromiumWebBrowser.cs | 6 -- CefSharp/Callback/TaskCompletionCallback.cs | 10 +- .../Callback/TaskDeleteCookiesCallback.cs | 9 +- CefSharp/Callback/TaskPrintToPdfCallback.cs | 9 +- CefSharp/Callback/TaskResolveCallback.cs | 9 +- CefSharp/Callback/TaskSetCookieCallback.cs | 9 +- CefSharp/CefSharp.csproj | 2 +- .../Partial/ChromiumWebBrowser.Partial.cs | 6 +- CefSharp/Internals/PendingTaskRepository.cs | 4 +- CefSharp/Internals/TaskExtensions.cs | 102 ------------------ .../JavascriptBindingExtensions.cs | 6 +- CefSharp/Visitor/TaskCookieVisitor.cs | 9 +- .../Visitor/TaskNavigationEntryVisitor.cs | 5 +- CefSharp/Visitor/TaskStringVisitor.cs | 4 +- CefSharp/WebBrowserExtensions.cs | 12 +-- NuGet/CefSharp.Common.nuspec | 18 ++-- NuGet/CefSharp.Common.props | 4 +- NuGet/CefSharp.Common.targets | 6 +- NuGet/CefSharp.OffScreen.nuspec | 11 +- NuGet/CefSharp.WinForms.nuspec | 11 +- NuGet/CefSharp.Wpf.nuspec | 11 +- NuGet/Readme.txt | 4 +- README.md | 2 +- 36 files changed, 96 insertions(+), 240 deletions(-) diff --git a/CefSharp.BrowserSubprocess.Core/CefSharp.BrowserSubprocess.Core.vcxproj b/CefSharp.BrowserSubprocess.Core/CefSharp.BrowserSubprocess.Core.vcxproj index f36309c26..c04101787 100644 --- a/CefSharp.BrowserSubprocess.Core/CefSharp.BrowserSubprocess.Core.vcxproj +++ b/CefSharp.BrowserSubprocess.Core/CefSharp.BrowserSubprocess.Core.vcxproj @@ -1,4 +1,4 @@ - + @@ -26,7 +26,7 @@ {6C4BB501-2F8E-48AC-9AB5-8CFB2D74185C} ManagedCProj CefSharpBrowserSubprocessCore - v4.5.2 + v4.6.2 10.0 @@ -261,4 +261,4 @@ - \ No newline at end of file + diff --git a/CefSharp.BrowserSubprocess/CefSharp.BrowserSubprocess.csproj b/CefSharp.BrowserSubprocess/CefSharp.BrowserSubprocess.csproj index 30ba63279..03728ee01 100644 --- a/CefSharp.BrowserSubprocess/CefSharp.BrowserSubprocess.csproj +++ b/CefSharp.BrowserSubprocess/CefSharp.BrowserSubprocess.csproj @@ -1,6 +1,6 @@ - net452 + net462 WinExe x86;x64 false diff --git a/CefSharp.BrowserSubprocess/app.config b/CefSharp.BrowserSubprocess/app.config index de8289320..ac5aa757c 100644 --- a/CefSharp.BrowserSubprocess/app.config +++ b/CefSharp.BrowserSubprocess/app.config @@ -1,3 +1,3 @@ - + diff --git a/CefSharp.Core.Runtime/CefSharp.Core.Runtime.vcxproj b/CefSharp.Core.Runtime/CefSharp.Core.Runtime.vcxproj index 535fc76a1..8e5c031f5 100644 --- a/CefSharp.Core.Runtime/CefSharp.Core.Runtime.vcxproj +++ b/CefSharp.Core.Runtime/CefSharp.Core.Runtime.vcxproj @@ -1,4 +1,4 @@ - + @@ -26,7 +26,7 @@ {7B495581-2271-4F41-9476-ACB86E8C864F} CefSharp ManagedCProj - v4.5.2 + v4.6.2 @@ -368,4 +368,4 @@ - \ No newline at end of file + diff --git a/CefSharp.Core.Runtime/Internals/CefBrowserHostWrapper.cpp b/CefSharp.Core.Runtime/Internals/CefBrowserHostWrapper.cpp index 143f278c3..c85427d4f 100644 --- a/CefSharp.Core.Runtime/Internals/CefBrowserHostWrapper.cpp +++ b/CefSharp.Core.Runtime/Internals/CefBrowserHostWrapper.cpp @@ -134,10 +134,7 @@ Task^ CefBrowserHostWrapper::GetZoomLevelAsync() if (CefCurrentlyOn(TID_UI)) { - auto taskSource = gcnew TaskCompletionSource(); - - CefSharp::Internals::TaskExtensions::TrySetResultAsync(taskSource, GetZoomLevelOnUI()); - return taskSource->Task; + return Task::FromResult(GetZoomLevelOnUI()); } return Cef::UIThreadTaskFactory->StartNew(gcnew Func(this, &CefBrowserHostWrapper::GetZoomLevelOnUI)); } diff --git a/CefSharp.Core.Runtime/Internals/ClientAdapter.cpp b/CefSharp.Core.Runtime/Internals/ClientAdapter.cpp index 0cc7c31cf..a5b994856 100644 --- a/CefSharp.Core.Runtime/Internals/ClientAdapter.cpp +++ b/CefSharp.Core.Runtime/Internals/ClientAdapter.cpp @@ -1489,7 +1489,7 @@ namespace CefSharp response->Message = StringUtils::ToClr(argList->GetString(2)); } - CefSharp::Internals::TaskExtensions::TrySetResultAsync(pendingTask, response); + pendingTask->TrySetResult(response); } handled = true; diff --git a/CefSharp.Core/CefSharp.Core.csproj b/CefSharp.Core/CefSharp.Core.csproj index 03f22f3fc..1f7efab95 100644 --- a/CefSharp.Core/CefSharp.Core.csproj +++ b/CefSharp.Core/CefSharp.Core.csproj @@ -1,6 +1,6 @@ - net452 + net462 Library CefSharp false diff --git a/CefSharp.Core/DevTools/DevToolsClient.cs b/CefSharp.Core/DevTools/DevToolsClient.cs index 805cb82fd..a88fad214 100644 --- a/CefSharp.Core/DevTools/DevToolsClient.cs +++ b/CefSharp.Core/DevTools/DevToolsClient.cs @@ -138,7 +138,7 @@ namespace CefSharp.DevTools throw new ObjectDisposedException(nameof(IBrowser)); } - var taskCompletionSource = new TaskCompletionSource(); + var taskCompletionSource = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var methodResultContext = new DevToolsMethodResponseContext( type: typeof(T), @@ -332,7 +332,7 @@ namespace CefSharp.DevTools /// /// Deserialize the JSON stream into a .Net object. /// For .Net Core/.Net 5.0 uses System.Text.Json - /// for .Net 4.5.2 uses System.Runtime.Serialization.Json + /// for .Net 4.6.2 uses System.Runtime.Serialization.Json /// /// Object type /// event Name @@ -359,7 +359,7 @@ namespace CefSharp.DevTools /// /// Deserialize the JSON stream into a .Net object. /// For .Net Core/.Net 5.0 uses System.Text.Json - /// for .Net 4.5.2 uses System.Runtime.Serialization.Json + /// for .Net 4.6.2 uses System.Runtime.Serialization.Json /// /// Object type /// JSON stream @@ -372,7 +372,7 @@ namespace CefSharp.DevTools /// /// Deserialize the JSON stream into a .Net object. /// For .Net Core/.Net 5.0 uses System.Text.Json - /// for .Net 4.5.2 uses System.Runtime.Serialization.Json + /// for .Net 4.6.2 uses System.Runtime.Serialization.Json /// /// Object type /// JSON stream diff --git a/CefSharp.Core/WebBrowserExtensionsEx.cs b/CefSharp.Core/WebBrowserExtensionsEx.cs index 9892ff52a..537f7cba3 100644 --- a/CefSharp.Core/WebBrowserExtensionsEx.cs +++ b/CefSharp.Core/WebBrowserExtensionsEx.cs @@ -39,13 +39,13 @@ namespace CefSharp return Task.FromResult(entry); } - var tcs = new TaskCompletionSource(); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); Cef.UIThreadTaskFactory.StartNew(delegate { var entry = host.GetVisibleNavigationEntry(); - tcs.TrySetResultAsync(entry); + tcs.TrySetResult(entry); }); return tcs.Task; @@ -107,7 +107,7 @@ namespace CefSharp throw new Exception("Frame is invalid, unable to continue."); } - var taskCompletionSource = new TaskCompletionSource(); + var taskCompletionSource = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); //Can be created on any valid CEF Thread, here we'll use the CEF UI Thread Cef.UIThreadTaskFactory.StartNew(delegate @@ -129,11 +129,11 @@ namespace CefSharp { if (req.RequestStatus == UrlRequestStatus.Success) { - taskCompletionSource.TrySetResultAsync(memoryStream.ToArray()); + taskCompletionSource.TrySetResult(memoryStream.ToArray()); } else { - taskCompletionSource.TrySetExceptionAsync(new Exception("RequestStatus:" + req.RequestStatus + ";StatusCode:" + req.Response.StatusCode)); + taskCompletionSource.TrySetException(new Exception("RequestStatus:" + req.RequestStatus + ";StatusCode:" + req.Response.StatusCode)); } }) .Build(); diff --git a/CefSharp.OffScreen/CefSharp.OffScreen.csproj b/CefSharp.OffScreen/CefSharp.OffScreen.csproj index 249e94b63..aff0664b7 100644 --- a/CefSharp.OffScreen/CefSharp.OffScreen.csproj +++ b/CefSharp.OffScreen/CefSharp.OffScreen.csproj @@ -1,6 +1,6 @@ - net452;net462 + net462 Library true ..\CefSharp.snk diff --git a/CefSharp.OffScreen/ChromiumWebBrowser.cs b/CefSharp.OffScreen/ChromiumWebBrowser.cs index 1144c64fb..8d0d17644 100644 --- a/CefSharp.OffScreen/ChromiumWebBrowser.cs +++ b/CefSharp.OffScreen/ChromiumWebBrowser.cs @@ -389,11 +389,11 @@ namespace CefSharp.OffScreen /// public Task CreateBrowserAsync(IWindowInfo windowInfo = null, IBrowserSettings browserSettings = null) { - var tcs = new TaskCompletionSource(); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); onAfterBrowserCreatedDelegate += new Action(b => { - tcs.TrySetResultAsync(b); + tcs.TrySetResult(b); }); try @@ -402,7 +402,7 @@ namespace CefSharp.OffScreen } catch(Exception ex) { - tcs.TrySetExceptionAsync(ex); + tcs.TrySetException(ex); } return tcs.Task; @@ -520,7 +520,7 @@ namespace CefSharp.OffScreen // Try our luck and see if there is already a screenshot, to save us creating a new thread for nothing. var screenshot = ScreenshotOrNull(blend); - var completionSource = new TaskCompletionSource(); + var completionSource = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); if (screenshot == null || ignoreExistingScreenshot) { @@ -539,7 +539,7 @@ namespace CefSharp.OffScreen } else { - completionSource.TrySetResultAsync(ScreenshotOrNull(blend)); + completionSource.TrySetResult(ScreenshotOrNull(blend)); } }; @@ -547,7 +547,7 @@ namespace CefSharp.OffScreen } else { - completionSource.TrySetResultAsync(screenshot); + completionSource.TrySetResult(screenshot); } return completionSource.Task; @@ -640,7 +640,7 @@ namespace CefSharp.OffScreen var scaledWidth = (int)(width * DeviceScaleFactor); var scaledHeight = (int)(height * DeviceScaleFactor); - var tcs = new TaskCompletionSource(); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); EventHandler handler = null; handler = (s, e) => @@ -649,7 +649,7 @@ namespace CefSharp.OffScreen { AfterPaint -= handler; - tcs.TrySetResultAsync(true); + tcs.TrySetResult(true); } }; @@ -692,7 +692,6 @@ namespace CefSharp.OffScreen } } -#if NETCOREAPP || NET462 /// /// Waits for the page rendering to be idle for . /// Rendering is considered to be idle when no events have occured @@ -750,7 +749,6 @@ namespace CefSharp.OffScreen throw; } } -#endif /// /// The javascript object repository, one repository per ChromiumWebBrowser instance. diff --git a/CefSharp.WinForms/CefSharp.WinForms.csproj b/CefSharp.WinForms/CefSharp.WinForms.csproj index 232089801..93318b092 100644 --- a/CefSharp.WinForms/CefSharp.WinForms.csproj +++ b/CefSharp.WinForms/CefSharp.WinForms.csproj @@ -1,6 +1,6 @@ - net452;net462 + net462 Library true ..\CefSharp.snk diff --git a/CefSharp.Wpf/CefSharp.Wpf.csproj b/CefSharp.Wpf/CefSharp.Wpf.csproj index ee02dfa5e..4599b4769 100644 --- a/CefSharp.Wpf/CefSharp.Wpf.csproj +++ b/CefSharp.Wpf/CefSharp.Wpf.csproj @@ -1,6 +1,6 @@ - net452;net462 + net462 Library false true diff --git a/CefSharp.Wpf/ChromiumWebBrowser.cs b/CefSharp.Wpf/ChromiumWebBrowser.cs index 16973f9e2..ea8151c2c 100644 --- a/CefSharp.Wpf/ChromiumWebBrowser.cs +++ b/CefSharp.Wpf/ChromiumWebBrowser.cs @@ -1776,7 +1776,6 @@ namespace CefSharp.Wpf } } -#if NETCOREAPP || NET462 /// protected override void OnDpiChanged(DpiScale oldDpi, DpiScale newDpi) { @@ -1784,7 +1783,6 @@ namespace CefSharp.Wpf base.OnDpiChanged(oldDpi, newDpi); } -#endif private void OnWindowStateChanged(object sender, EventArgs e) { @@ -2638,8 +2636,6 @@ namespace CefSharp.Wpf /// correspond to 96, 120, 144, 192 DPI (referred to as 100%, 125%, 150%, 200% in the Windows GUI). /// /// new DPI - /// .Net 4.6.2 adds HwndSource.DpiChanged which could be used to automatically - /// handle DPI change, unfortunately we still target .Net 4.5.2 public virtual void NotifyDpiChange(float newDpi) { //Do nothing @@ -2680,7 +2676,6 @@ namespace CefSharp.Wpf } } -#if NETCOREAPP || NET462 /// /// Waits for the page rendering to be idle for . /// Rendering is considered to be idle when no events have occured @@ -2738,7 +2733,6 @@ namespace CefSharp.Wpf throw; } } -#endif /// /// Legacy keyboard handler uses WindowProc callback interceptor to forward keypress events diff --git a/CefSharp/Callback/TaskCompletionCallback.cs b/CefSharp/Callback/TaskCompletionCallback.cs index 56428f4ce..c930749da 100644 --- a/CefSharp/Callback/TaskCompletionCallback.cs +++ b/CefSharp/Callback/TaskCompletionCallback.cs @@ -4,7 +4,6 @@ using System; using System.Threading.Tasks; -using CefSharp.Internals; namespace CefSharp { @@ -22,14 +21,14 @@ namespace CefSharp /// public TaskCompletionCallback() { - taskCompletionSource = new TaskCompletionSource(); + taskCompletionSource = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); } void ICompletionCallback.OnComplete() { onComplete = true; - taskCompletionSource.TrySetResultAsync(true); + taskCompletionSource.TrySetResult(true); } /// @@ -50,11 +49,10 @@ namespace CefSharp var task = taskCompletionSource.Task; //If onComplete is false then ICompletionCallback.OnComplete was never called, - //so we'll set the result to false. Calling TrySetResultAsync multiple times - //can result in the issue outlined in https://github.com/cefsharp/CefSharp/pull/2349 + //so we'll set the result to false. if (onComplete == false && task.IsCompleted == false) { - taskCompletionSource.TrySetResultAsync(false); + taskCompletionSource.TrySetResult(false); } isDisposed = true; diff --git a/CefSharp/Callback/TaskDeleteCookiesCallback.cs b/CefSharp/Callback/TaskDeleteCookiesCallback.cs index 13545fdf9..cc7fc1201 100644 --- a/CefSharp/Callback/TaskDeleteCookiesCallback.cs +++ b/CefSharp/Callback/TaskDeleteCookiesCallback.cs @@ -27,14 +27,14 @@ namespace CefSharp /// public TaskDeleteCookiesCallback() { - taskCompletionSource = new TaskCompletionSource(); + taskCompletionSource = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); } void IDeleteCookiesCallback.OnComplete(int numDeleted) { onComplete = true; - taskCompletionSource.TrySetResultAsync(numDeleted); + taskCompletionSource.TrySetResult(numDeleted); } /// @@ -54,11 +54,10 @@ namespace CefSharp var task = taskCompletionSource.Task; //If onComplete is false then IDeleteCookiesCallback.OnComplete was never called, - //so we'll set the result to false. Calling TrySetResultAsync multiple times - //can result in the issue outlined in https://github.com/cefsharp/CefSharp/pull/2349 + //so we'll set the result to false. if (onComplete == false && task.IsCompleted == false) { - taskCompletionSource.TrySetResultAsync(InvalidNoOfCookiesDeleted); + taskCompletionSource.TrySetResult(InvalidNoOfCookiesDeleted); } isDisposed = true; diff --git a/CefSharp/Callback/TaskPrintToPdfCallback.cs b/CefSharp/Callback/TaskPrintToPdfCallback.cs index dcf1d1a5f..18bc66ac2 100644 --- a/CefSharp/Callback/TaskPrintToPdfCallback.cs +++ b/CefSharp/Callback/TaskPrintToPdfCallback.cs @@ -13,7 +13,7 @@ namespace CefSharp /// public sealed class TaskPrintToPdfCallback : IPrintToPdfCallback { - private readonly TaskCompletionSource taskCompletionSource = new TaskCompletionSource(); + private readonly TaskCompletionSource taskCompletionSource = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); private volatile bool isDisposed; private bool onComplete; //Only ever accessed on the same CEF thread, so no need for thread safety @@ -29,7 +29,7 @@ namespace CefSharp { onComplete = true; - taskCompletionSource.TrySetResultAsync(ok); + taskCompletionSource.TrySetResult(ok); } bool IPrintToPdfCallback.IsDisposed @@ -42,11 +42,10 @@ namespace CefSharp var task = taskCompletionSource.Task; //If onComplete is false then IPrintToPdfCallback.OnPdfPrintFinished was never called, - //so we'll set the result to false. Calling TrySetResultAsync multiple times - //can result in the issue outlined in https://github.com/cefsharp/CefSharp/pull/2349 + //so we'll set the result to false. if (onComplete == false && task.IsCompleted == false) { - taskCompletionSource.TrySetResultAsync(false); + taskCompletionSource.TrySetResult(false); } isDisposed = true; diff --git a/CefSharp/Callback/TaskResolveCallback.cs b/CefSharp/Callback/TaskResolveCallback.cs index 1ea00e2c8..ccbf0e146 100644 --- a/CefSharp/Callback/TaskResolveCallback.cs +++ b/CefSharp/Callback/TaskResolveCallback.cs @@ -23,14 +23,14 @@ namespace CefSharp /// public TaskResolveCallback() { - taskCompletionSource = new TaskCompletionSource(); + taskCompletionSource = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); } void IResolveCallback.OnResolveCompleted(CefErrorCode result, IList resolvedIpAddresses) { onComplete = true; - taskCompletionSource.TrySetResultAsync(new ResolveCallbackResult(result, resolvedIpAddresses)); + taskCompletionSource.TrySetResult(new ResolveCallbackResult(result, resolvedIpAddresses)); } bool IResolveCallback.IsDisposed @@ -51,11 +51,10 @@ namespace CefSharp var task = taskCompletionSource.Task; //If onComplete is false then IResolveCallback.OnResolveCompleted was never called, - //so we'll set the result to false. Calling TrySetResultAsync multiple times - //can result in the issue outlined in https://github.com/cefsharp/CefSharp/pull/2349 + //so we'll set the result to false. if (onComplete == false && task.IsCompleted == false) { - taskCompletionSource.TrySetResultAsync(new ResolveCallbackResult(CefErrorCode.Unexpected, null)); + taskCompletionSource.TrySetResult(new ResolveCallbackResult(CefErrorCode.Unexpected, null)); } isDisposed = true; diff --git a/CefSharp/Callback/TaskSetCookieCallback.cs b/CefSharp/Callback/TaskSetCookieCallback.cs index dffcaaae6..28126ca50 100644 --- a/CefSharp/Callback/TaskSetCookieCallback.cs +++ b/CefSharp/Callback/TaskSetCookieCallback.cs @@ -22,14 +22,14 @@ namespace CefSharp /// public TaskSetCookieCallback() { - taskCompletionSource = new TaskCompletionSource(); + taskCompletionSource = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); } void ISetCookieCallback.OnComplete(bool success) { onComplete = true; - taskCompletionSource.TrySetResultAsync(success); + taskCompletionSource.TrySetResult(success); } /// @@ -50,11 +50,10 @@ namespace CefSharp var task = taskCompletionSource.Task; //If onComplete is false then ISetCookieCallback.OnComplete was never called, - //so we'll set the result to false. Calling TrySetResultAsync multiple times - //can result in the issue outlined in https://github.com/cefsharp/CefSharp/pull/2349 + //so we'll set the result to false. if (onComplete == false && task.IsCompleted == false) { - taskCompletionSource.TrySetResultAsync(false); + taskCompletionSource.TrySetResult(false); } isDisposed = true; diff --git a/CefSharp/CefSharp.csproj b/CefSharp/CefSharp.csproj index 900b025ca..1d14689da 100644 --- a/CefSharp/CefSharp.csproj +++ b/CefSharp/CefSharp.csproj @@ -1,6 +1,6 @@ - net452 + net462 Library false true diff --git a/CefSharp/Internals/Partial/ChromiumWebBrowser.Partial.cs b/CefSharp/Internals/Partial/ChromiumWebBrowser.Partial.cs index 50f4c2d6d..c9c00ef55 100644 --- a/CefSharp/Internals/Partial/ChromiumWebBrowser.Partial.cs +++ b/CefSharp/Internals/Partial/ChromiumWebBrowser.Partial.cs @@ -51,7 +51,7 @@ namespace CefSharp.WinForms /// /// Initial browser load task complection source /// - private TaskCompletionSource initialLoadTaskCompletionSource = new TaskCompletionSource(); + private TaskCompletionSource initialLoadTaskCompletionSource = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); /// /// Initial browser load action @@ -458,7 +458,7 @@ namespace CefSharp.WinForms statusCode = -1; } - initialLoadTaskCompletionSource.TrySetResultAsync(new LoadUrlAsyncResponse(CefErrorCode.None, statusCode)); + initialLoadTaskCompletionSource.TrySetResult(new LoadUrlAsyncResponse(CefErrorCode.None, statusCode)); } else if (errorCode.HasValue) { @@ -471,7 +471,7 @@ namespace CefSharp.WinForms initialLoadAction = null; - initialLoadTaskCompletionSource.TrySetResultAsync(new LoadUrlAsyncResponse(errorCode.Value, -1)); + initialLoadTaskCompletionSource.TrySetResult(new LoadUrlAsyncResponse(errorCode.Value, -1)); } } diff --git a/CefSharp/Internals/PendingTaskRepository.cs b/CefSharp/Internals/PendingTaskRepository.cs index 3dae39c5e..3a867c9a7 100644 --- a/CefSharp/Internals/PendingTaskRepository.cs +++ b/CefSharp/Internals/PendingTaskRepository.cs @@ -33,7 +33,7 @@ namespace CefSharp.Internals /// The unique id of the newly created pending task and the newly created . public KeyValuePair> CreatePendingTask(TimeSpan? timeout = null) { - var taskCompletionSource = new TaskCompletionSource(); + var taskCompletionSource = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var id = Interlocked.Increment(ref lastId); pendingTasks.TryAdd(id, taskCompletionSource); @@ -54,7 +54,7 @@ namespace CefSharp.Internals /// The unique id of the newly created pending task and the newly created . public KeyValuePair> CreateJavascriptCallbackPendingTask(long id, TimeSpan? timeout = null) { - var taskCompletionSource = new TaskCompletionSource(); + var taskCompletionSource = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); callbackPendingTasks.TryAdd(id, taskCompletionSource); diff --git a/CefSharp/Internals/TaskExtensions.cs b/CefSharp/Internals/TaskExtensions.cs index 6b9e830ae..6b64d0d4d 100644 --- a/CefSharp/Internals/TaskExtensions.cs +++ b/CefSharp/Internals/TaskExtensions.cs @@ -15,64 +15,6 @@ namespace CefSharp.Internals /// public static class TaskExtensions { - /// Creates a new Task that mirrors the supplied task but that will be canceled after the specified timeout. - /// Specifies the type of data contained in the task. - /// The task. - /// The timeout. - /// The new Task that may time out. - public static Task WithTimeout(this Task task, TimeSpan timeout) - { - var result = new TaskCompletionSource(task.AsyncState); - var timer = new Timer(state => ((TaskCompletionSource)state).TrySetCanceled(), result, timeout, TimeSpan.FromMilliseconds(-1)); - task.ContinueWith(t => - { - timer.Dispose(); - result.TrySetFromTask(t); - }, TaskContinuationOptions.ExecuteSynchronously); - return result.Task; - } - - /// Attempts to transfer the result of a Task to the TaskCompletionSource. - /// Specifies the type of the result. - /// The TaskCompletionSource. - /// The task whose completion results should be transfered. - /// Whether the transfer could be completed. - public static bool TrySetFromTask(this TaskCompletionSource resultSetter, Task task) - { - switch (task.Status) - { - case TaskStatus.RanToCompletion: - return resultSetter.TrySetResult(task is Task ? ((Task)task).Result : default(TResult)); - case TaskStatus.Faulted: - return resultSetter.TrySetException(task.Exception.InnerExceptions); - case TaskStatus.Canceled: - return resultSetter.TrySetCanceled(); - default: - throw new InvalidOperationException("The task was not completed."); - } - } - /// Attempts to transfer the result of a Task to the TaskCompletionSource. - /// Specifies the type of the result. - /// The TaskCompletionSource. - /// The task whose completion results should be transfered. - /// Whether the transfer could be completed. - public static bool TrySetFromTask(this TaskCompletionSource resultSetter, Task task) - { - return TrySetFromTask(resultSetter, (Task)task); - } - - public static Task FromResult(T value) - { - var tcs = new TaskCompletionSource(); - tcs.SetResult(value); - return tcs.Task; - } - - public static TaskCompletionSource WithTimeout(this TaskCompletionSource taskCompletionSource, TimeSpan timeout) - { - return WithTimeout(taskCompletionSource, timeout, null); - } - public static TaskCompletionSource WithTimeout(this TaskCompletionSource taskCompletionSource, TimeSpan timeout, Action cancelled) { Timer timer = null; @@ -91,49 +33,5 @@ namespace CefSharp.Internals return taskCompletionSource; } - - /// - /// Set the TaskCompletionSource in an async fashion. This prevents the Task Continuation being executed sync on the same thread - /// This is required otherwise continuations will happen on CEF UI threads - /// - /// Generic param - /// tcs - /// result - public static void TrySetResultAsync(this TaskCompletionSource taskCompletionSource, TResult result) - { - Task.Factory.StartNew(delegate - { - taskCompletionSource.TrySetResult(result); - }, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default); - } - - /// - /// Calls in an async fashion. This prevents the Task Continuation being executed sync on the same thread - /// This is required otherwise continuations will happen on CEF UI threads - /// - /// Generic param - /// tcs - /// exception - public static void TrySetExceptionAsync(this TaskCompletionSource taskCompletionSource, Exception ex) - { - Task.Factory.StartNew(delegate - { - taskCompletionSource.TrySetException(ex); - }, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default); - } - - /// - /// Calls in an async fashion. This prevents the Task Continuation being executed sync on the same thread - /// This is required otherwise continuations will happen on CEF UI threads - /// - /// Generic param - /// tcs - public static void TrySetCanceledAsync(this TaskCompletionSource taskCompletionSource) - { - Task.Factory.StartNew(delegate - { - taskCompletionSource.TrySetCanceled(); - }, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default); - } } } diff --git a/CefSharp/JavascriptBinding/JavascriptBindingExtensions.cs b/CefSharp/JavascriptBinding/JavascriptBindingExtensions.cs index 536a1f48c..88721922a 100644 --- a/CefSharp/JavascriptBinding/JavascriptBindingExtensions.cs +++ b/CefSharp/JavascriptBinding/JavascriptBindingExtensions.cs @@ -23,7 +23,7 @@ namespace CefSharp /// List of objects that were bound public static Task> EnsureObjectBoundAsync(this IWebBrowser browser, params string[] names) { - var objBoundTasks = new TaskCompletionSource>(); + var objBoundTasks = new TaskCompletionSource>(TaskCreationOptions.RunContinuationsAsynchronously); EventHandler handler = null; handler = (sender, args) => @@ -34,11 +34,11 @@ namespace CefSharp var allObjectsBound = names.ToList().SequenceEqual(args.ObjectNames); if (allObjectsBound) { - objBoundTasks.SetResult(args.ObjectNames); + objBoundTasks.TrySetResult(args.ObjectNames); } else { - objBoundTasks.SetException(new Exception("Not all objects were bound successfully, bound objects were " + string.Join(",", args.ObjectNames))); + objBoundTasks.TrySetException(new Exception("Not all objects were bound successfully, bound objects were " + string.Join(",", args.ObjectNames))); } }; diff --git a/CefSharp/Visitor/TaskCookieVisitor.cs b/CefSharp/Visitor/TaskCookieVisitor.cs index f1bd9cb8b..7ff6881e4 100644 --- a/CefSharp/Visitor/TaskCookieVisitor.cs +++ b/CefSharp/Visitor/TaskCookieVisitor.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using CefSharp.Internals; namespace CefSharp { @@ -23,7 +22,7 @@ namespace CefSharp /// public TaskCookieVisitor() { - taskCompletionSource = new TaskCompletionSource>(); + taskCompletionSource = new TaskCompletionSource>(TaskCreationOptions.RunContinuationsAsynchronously); list = new List(); } @@ -34,8 +33,7 @@ namespace CefSharp if (count == (total - 1)) { - //Set the result on the ThreadPool so the Task continuation is not run on the CEF UI Thread - taskCompletionSource.TrySetResultAsync(list); + taskCompletionSource.TrySetResult(list); } return true; @@ -46,8 +44,7 @@ namespace CefSharp { if (list != null && list.Count == 0) { - //Set the result on the ThreadPool so the Task continuation is not run on the CEF UI Thread - taskCompletionSource.TrySetResultAsync(list); + taskCompletionSource.TrySetResult(list); } list = null; diff --git a/CefSharp/Visitor/TaskNavigationEntryVisitor.cs b/CefSharp/Visitor/TaskNavigationEntryVisitor.cs index c8088b8d3..8c10d2403 100644 --- a/CefSharp/Visitor/TaskNavigationEntryVisitor.cs +++ b/CefSharp/Visitor/TaskNavigationEntryVisitor.cs @@ -23,7 +23,7 @@ namespace CefSharp /// public TaskNavigationEntryVisitor() { - taskCompletionSource = new TaskCompletionSource>(); + taskCompletionSource = new TaskCompletionSource>(TaskCreationOptions.RunContinuationsAsynchronously); list = new List(); } @@ -40,8 +40,7 @@ namespace CefSharp { if (list != null) { - //Set the result on the ThreadPool so the Task continuation is not run on the CEF UI Thread - taskCompletionSource.TrySetResultAsync(list); + taskCompletionSource.TrySetResult(list); } list = null; diff --git a/CefSharp/Visitor/TaskStringVisitor.cs b/CefSharp/Visitor/TaskStringVisitor.cs index b82e56521..c8a0fc8fc 100644 --- a/CefSharp/Visitor/TaskStringVisitor.cs +++ b/CefSharp/Visitor/TaskStringVisitor.cs @@ -21,7 +21,7 @@ namespace CefSharp /// public TaskStringVisitor() { - taskCompletionSource = new TaskCompletionSource(); + taskCompletionSource = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); } /// @@ -30,7 +30,7 @@ namespace CefSharp /// string (result of async execution) void IStringVisitor.Visit(string str) { - taskCompletionSource.TrySetResultAsync(str); + taskCompletionSource.TrySetResult(str); } /// diff --git a/CefSharp/WebBrowserExtensions.cs b/CefSharp/WebBrowserExtensions.cs index 4ca10dd4e..a17bb9a32 100644 --- a/CefSharp/WebBrowserExtensions.cs +++ b/CefSharp/WebBrowserExtensions.cs @@ -424,7 +424,7 @@ namespace CefSharp throw new ArgumentNullException(nameof(url)); } - var tcs = new TaskCompletionSource(); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); EventHandler loadErrorHandler = null; EventHandler loadingStateChangeHandler = null; @@ -447,7 +447,7 @@ namespace CefSharp //Ensure our continuation is executed on the ThreadPool //For the .Net Core implementation we could use //TaskCreationOptions.RunContinuationsAsynchronously - tcs.TrySetResultAsync(new LoadUrlAsyncResponse(args.ErrorCode, -1)); + tcs.TrySetResult(new LoadUrlAsyncResponse(args.ErrorCode, -1)); }; loadingStateChangeHandler = (sender, args) => @@ -478,7 +478,7 @@ namespace CefSharp //Ensure our continuation is executed on the ThreadPool //For the .Net Core implementation we could use //TaskCreationOptions.RunContinuationsAsynchronously - tcs.TrySetResultAsync(new LoadUrlAsyncResponse(statusCode == -1 ? CefErrorCode.Failed : CefErrorCode.None, statusCode)); + tcs.TrySetResult(new LoadUrlAsyncResponse(statusCode == -1 ? CefErrorCode.Failed : CefErrorCode.None, statusCode)); } }; @@ -520,7 +520,7 @@ namespace CefSharp { ThrowExceptionIfChromiumWebBrowserDisposed(chromiumWebBrowser); - var tcs = new TaskCompletionSource(); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); EventHandler loadErrorHandler = null; EventHandler loadingStateChangeHandler = null; @@ -543,7 +543,7 @@ namespace CefSharp //Ensure our continuation is executed on the ThreadPool //For the .Net Core implementation we could use //TaskCreationOptions.RunContinuationsAsynchronously - tcs.TrySetResultAsync(new WaitForNavigationAsyncResponse(args.ErrorCode, -1)); + tcs.TrySetResult(new WaitForNavigationAsyncResponse(args.ErrorCode, -1)); }; loadingStateChangeHandler = (sender, args) => @@ -574,7 +574,7 @@ namespace CefSharp //Ensure our continuation is executed on the ThreadPool //For the .Net Core implementation we could use //TaskCreationOptions.RunContinuationsAsynchronously - tcs.TrySetResultAsync(new WaitForNavigationAsyncResponse(statusCode == -1 ? CefErrorCode.Failed : CefErrorCode.None, statusCode)); + tcs.TrySetResult(new WaitForNavigationAsyncResponse(statusCode == -1 ? CefErrorCode.Failed : CefErrorCode.None, statusCode)); } }; diff --git a/NuGet/CefSharp.Common.nuspec b/NuGet/CefSharp.Common.nuspec index de89adcef..80fe0e3c5 100644 --- a/NuGet/CefSharp.Common.nuspec +++ b/NuGet/CefSharp.Common.nuspec @@ -12,21 +12,21 @@ chrome browser Copyright © The CefSharp Authors - + - + - - - - - - + + + + + + - diff --git a/NuGet/CefSharp.Common.props b/NuGet/CefSharp.Common.props index 580605831..60d131fbb 100644 --- a/NuGet/CefSharp.Common.props +++ b/NuGet/CefSharp.Common.props @@ -5,9 +5,9 @@ - + - + diff --git a/NuGet/CefSharp.Common.targets b/NuGet/CefSharp.Common.targets index 7347aa724..203ba2142 100644 --- a/NuGet/CefSharp.Common.targets +++ b/NuGet/CefSharp.Common.targets @@ -397,7 +397,7 @@ - + @@ -408,7 +408,7 @@ - + @@ -427,7 +427,7 @@ $(CefRedist64TargetDir)x64\ - <_CefSharpCommonManagedDll Include="$(MSBuildThisFileDirectory)..\lib\net452\CefSharp.dll" /> + <_CefSharpCommonManagedDll Include="$(MSBuildThisFileDirectory)..\lib\net462\CefSharp.dll" /> <_CefSharpCommonBinaries32 Include="$(MSBuildThisFileDirectory)..\CefSharp\x86\*.*" /> <_CefSharpCommonBinaries64 Include="$(MSBuildThisFileDirectory)..\CefSharp\x64\*.*" /> diff --git a/NuGet/CefSharp.OffScreen.nuspec b/NuGet/CefSharp.OffScreen.nuspec index 4a0c1c3f2..6854ff636 100644 --- a/NuGet/CefSharp.OffScreen.nuspec +++ b/NuGet/CefSharp.OffScreen.nuspec @@ -12,10 +12,7 @@ osr chrome browser chromium-embedded cefsharp Copyright © The CefSharp Authors - - - - + @@ -27,11 +24,7 @@ - - - - - + diff --git a/NuGet/CefSharp.WinForms.nuspec b/NuGet/CefSharp.WinForms.nuspec index ee8d068ee..8606d1027 100644 --- a/NuGet/CefSharp.WinForms.nuspec +++ b/NuGet/CefSharp.WinForms.nuspec @@ -12,10 +12,7 @@ winforms chrome browser chromium-embedded cefsharp Copyright © The CefSharp Authors - - - - + @@ -27,11 +24,7 @@ - - - - - + diff --git a/NuGet/CefSharp.Wpf.nuspec b/NuGet/CefSharp.Wpf.nuspec index 22421d581..dabad3b01 100644 --- a/NuGet/CefSharp.Wpf.nuspec +++ b/NuGet/CefSharp.Wpf.nuspec @@ -12,10 +12,7 @@ wpf chrome browser chromium-embedded cefsharp Copyright © The CefSharp Authors - - - - + @@ -27,11 +24,7 @@ - - - - - + diff --git a/NuGet/Readme.txt b/NuGet/Readme.txt index 3d6c0effa..e72766a54 100644 --- a/NuGet/Readme.txt +++ b/NuGet/Readme.txt @@ -18,11 +18,11 @@ Deployment: What's New: See https://github.com/cefsharp/CefSharp/releases IMPORTANT NOTE - Visual C++ 2019 or greater is required - IMPORTANT NOTE - .NET Framework 4.5.2 or greater is required. + IMPORTANT NOTE - .NET Framework 4.6.2 or greater is required. IMPORTANT NOTE - Chromium support for Windows 7/8/8.1 ends with version 109, starting with version 110 a minimum of Windows 10 is required. Basic Troubleshooting: - - Minimum of .Net 4.5.2 + - Minimum of .Net 4.6.2 - Minimum of `Visual C++ 2019 Redist` is installed (either `x86` or `x64` depending on your application). - Please ensure your binaries directory contains these required dependencies: * libcef.dll (Chromium Embedded Framework Core library) diff --git a/README.md b/README.md index 019c95fa0..6dc208e10 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,7 @@ If you're new to `CefSharp` and are downloading the source to check it out, plea | Branch | CEF Version | VC++ Version | .Net Version | Status | |-----------------------------------------------------------------------|------|-------|---------|-----------------| -| [master](https://github.com/cefsharp/CefSharp/) | 5615 | 2019* | 4.5.2** | Development | +| [master](https://github.com/cefsharp/CefSharp/) | 5615 | 2019* | 4.6.2** | Development | | [cefsharp/113](https://github.com/cefsharp/CefSharp/tree/cefsharp/113)| 5615 | 2019* | 4.5.2** | **Release** | | [cefsharp/112](https://github.com/cefsharp/CefSharp/tree/cefsharp/112)| 5615 | 2019* | 4.5.2** | Unsupported | | [cefsharp/111](https://github.com/cefsharp/CefSharp/tree/cefsharp/111)| 5563 | 2019* | 4.5.2** | Unsupported |