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
This commit is contained in:
Alex Maitland
2023-06-10 07:33:20 +10:00
committed by GitHub
parent 252105271f
commit 1def8a7937
36 changed files with 96 additions and 240 deletions
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\cef.sdk.114.2.10\build\cef.sdk.props" Condition="Exists('..\packages\cef.sdk.114.2.10\build\cef.sdk.props')" />
<Import Project="..\packages\Microsoft.SourceLink.GitHub.1.0.0\build\Microsoft.SourceLink.GitHub.props" Condition="Exists('..\packages\Microsoft.SourceLink.GitHub.1.0.0\build\Microsoft.SourceLink.GitHub.props')" />
@@ -26,7 +26,7 @@
<ProjectGuid>{6C4BB501-2F8E-48AC-9AB5-8CFB2D74185C}</ProjectGuid>
<Keyword>ManagedCProj</Keyword>
<RootNamespace>CefSharpBrowserSubprocessCore</RootNamespace>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
@@ -261,4 +261,4 @@
<Import Project="..\packages\Microsoft.SourceLink.Common.1.0.0\build\Microsoft.SourceLink.Common.targets" Condition="Exists('..\packages\Microsoft.SourceLink.Common.1.0.0\build\Microsoft.SourceLink.Common.targets')" />
<Import Project="..\packages\Microsoft.SourceLink.GitHub.1.0.0\build\Microsoft.SourceLink.GitHub.targets" Condition="Exists('..\packages\Microsoft.SourceLink.GitHub.1.0.0\build\Microsoft.SourceLink.GitHub.targets')" />
</ImportGroup>
</Project>
</Project>
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net452</TargetFramework>
<TargetFramework>net462</TargetFramework>
<OutputType>WinExe</OutputType>
<Platforms>x86;x64</Platforms>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
+1 -1
View File
@@ -1,3 +1,3 @@
<?xml version="1.0"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/></startup></configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/></startup></configuration>
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\cef.sdk.114.2.10\build\cef.sdk.props" Condition="Exists('..\packages\cef.sdk.114.2.10\build\cef.sdk.props')" />
<Import Project="..\packages\Microsoft.SourceLink.GitHub.1.0.0\build\Microsoft.SourceLink.GitHub.props" Condition="Exists('..\packages\Microsoft.SourceLink.GitHub.1.0.0\build\Microsoft.SourceLink.GitHub.props')" />
@@ -26,7 +26,7 @@
<ProjectGuid>{7B495581-2271-4F41-9476-ACB86E8C864F}</ProjectGuid>
<RootNamespace>CefSharp</RootNamespace>
<Keyword>ManagedCProj</Keyword>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<Import Project="..\CefSharp.props" />
@@ -368,4 +368,4 @@
<Import Project="..\packages\Microsoft.SourceLink.Common.1.0.0\build\Microsoft.SourceLink.Common.targets" Condition="Exists('..\packages\Microsoft.SourceLink.Common.1.0.0\build\Microsoft.SourceLink.Common.targets')" />
<Import Project="..\packages\Microsoft.SourceLink.GitHub.1.0.0\build\Microsoft.SourceLink.GitHub.targets" Condition="Exists('..\packages\Microsoft.SourceLink.GitHub.1.0.0\build\Microsoft.SourceLink.GitHub.targets')" />
</ImportGroup>
</Project>
</Project>
@@ -134,10 +134,7 @@ Task<double>^ CefBrowserHostWrapper::GetZoomLevelAsync()
if (CefCurrentlyOn(TID_UI))
{
auto taskSource = gcnew TaskCompletionSource<double>();
CefSharp::Internals::TaskExtensions::TrySetResultAsync<double>(taskSource, GetZoomLevelOnUI());
return taskSource->Task;
return Task::FromResult(GetZoomLevelOnUI());
}
return Cef::UIThreadTaskFactory->StartNew(gcnew Func<double>(this, &CefBrowserHostWrapper::GetZoomLevelOnUI));
}
@@ -1489,7 +1489,7 @@ namespace CefSharp
response->Message = StringUtils::ToClr(argList->GetString(2));
}
CefSharp::Internals::TaskExtensions::TrySetResultAsync<JavascriptResponse^>(pendingTask, response);
pendingTask->TrySetResult(response);
}
handled = true;
+1 -1
View File
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net452</TargetFramework>
<TargetFramework>net462</TargetFramework>
<OutputType>Library</OutputType>
<RootNamespace>CefSharp</RootNamespace>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
+4 -4
View File
@@ -138,7 +138,7 @@ namespace CefSharp.DevTools
throw new ObjectDisposedException(nameof(IBrowser));
}
var taskCompletionSource = new TaskCompletionSource<T>();
var taskCompletionSource = new TaskCompletionSource<T>(TaskCreationOptions.RunContinuationsAsynchronously);
var methodResultContext = new DevToolsMethodResponseContext(
type: typeof(T),
@@ -332,7 +332,7 @@ namespace CefSharp.DevTools
/// <summary>
/// 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
/// </summary>
/// <typeparam name="T">Object type</typeparam>
/// <param name="eventName">event Name</param>
@@ -359,7 +359,7 @@ namespace CefSharp.DevTools
/// <summary>
/// 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
/// </summary>
/// <typeparam name="T">Object type</typeparam>
/// <param name="stream">JSON stream</param>
@@ -372,7 +372,7 @@ namespace CefSharp.DevTools
/// <summary>
/// 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
/// </summary>
/// <param name="type">Object type</param>
/// <param name="stream">JSON stream</param>
+5 -5
View File
@@ -39,13 +39,13 @@ namespace CefSharp
return Task.FromResult<NavigationEntry>(entry);
}
var tcs = new TaskCompletionSource<NavigationEntry>();
var tcs = new TaskCompletionSource<NavigationEntry>(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<byte[]>();
var taskCompletionSource = new TaskCompletionSource<byte[]>(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();
+1 -1
View File
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net452;net462</TargetFrameworks>
<TargetFrameworks>net462</TargetFrameworks>
<OutputType>Library</OutputType>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\CefSharp.snk</AssemblyOriginatorKeyFile>
+8 -10
View File
@@ -389,11 +389,11 @@ namespace CefSharp.OffScreen
/// </returns>
public Task<IBrowser> CreateBrowserAsync(IWindowInfo windowInfo = null, IBrowserSettings browserSettings = null)
{
var tcs = new TaskCompletionSource<IBrowser>();
var tcs = new TaskCompletionSource<IBrowser>(TaskCreationOptions.RunContinuationsAsynchronously);
onAfterBrowserCreatedDelegate += new Action<IBrowser>(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<Bitmap>();
var completionSource = new TaskCompletionSource<Bitmap>(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<bool>();
var tcs = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
EventHandler<OnPaintEventArgs> 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
/// <summary>
/// Waits for the page rendering to be idle for <paramref name="idleTimeInMs"/>.
/// Rendering is considered to be idle when no <see cref="Paint"/> events have occured
@@ -750,7 +749,6 @@ namespace CefSharp.OffScreen
throw;
}
}
#endif
/// <summary>
/// The javascript object repository, one repository per ChromiumWebBrowser instance.
+1 -1
View File
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net452;net462</TargetFrameworks>
<TargetFrameworks>net462</TargetFrameworks>
<OutputType>Library</OutputType>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\CefSharp.snk</AssemblyOriginatorKeyFile>
+1 -1
View File
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net452;net462</TargetFrameworks>
<TargetFrameworks>net462</TargetFrameworks>
<OutputType>Library</OutputType>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<UseWPF>true</UseWPF>
-6
View File
@@ -1776,7 +1776,6 @@ namespace CefSharp.Wpf
}
}
#if NETCOREAPP || NET462
/// <inheritdoc/>
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).
/// </summary>
/// <param name="newDpi">new DPI</param>
/// <remarks>.Net 4.6.2 adds HwndSource.DpiChanged which could be used to automatically
/// handle DPI change, unfortunately we still target .Net 4.5.2</remarks>
public virtual void NotifyDpiChange(float newDpi)
{
//Do nothing
@@ -2680,7 +2676,6 @@ namespace CefSharp.Wpf
}
}
#if NETCOREAPP || NET462
/// <summary>
/// Waits for the page rendering to be idle for <paramref name="idleTimeInMs"/>.
/// Rendering is considered to be idle when no <see cref="Paint"/> events have occured
@@ -2738,7 +2733,6 @@ namespace CefSharp.Wpf
throw;
}
}
#endif
/// <summary>
/// Legacy keyboard handler uses WindowProc callback interceptor to forward keypress events
+4 -6
View File
@@ -4,7 +4,6 @@
using System;
using System.Threading.Tasks;
using CefSharp.Internals;
namespace CefSharp
{
@@ -22,14 +21,14 @@ namespace CefSharp
/// </summary>
public TaskCompletionCallback()
{
taskCompletionSource = new TaskCompletionSource<bool>();
taskCompletionSource = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
}
void ICompletionCallback.OnComplete()
{
onComplete = true;
taskCompletionSource.TrySetResultAsync(true);
taskCompletionSource.TrySetResult(true);
}
/// <summary>
@@ -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;
@@ -27,14 +27,14 @@ namespace CefSharp
/// </summary>
public TaskDeleteCookiesCallback()
{
taskCompletionSource = new TaskCompletionSource<int>();
taskCompletionSource = new TaskCompletionSource<int>(TaskCreationOptions.RunContinuationsAsynchronously);
}
void IDeleteCookiesCallback.OnComplete(int numDeleted)
{
onComplete = true;
taskCompletionSource.TrySetResultAsync(numDeleted);
taskCompletionSource.TrySetResult(numDeleted);
}
/// <summary>
@@ -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;
+4 -5
View File
@@ -13,7 +13,7 @@ namespace CefSharp
/// </summary>
public sealed class TaskPrintToPdfCallback : IPrintToPdfCallback
{
private readonly TaskCompletionSource<bool> taskCompletionSource = new TaskCompletionSource<bool>();
private readonly TaskCompletionSource<bool> taskCompletionSource = new TaskCompletionSource<bool>(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;
+4 -5
View File
@@ -23,14 +23,14 @@ namespace CefSharp
/// </summary>
public TaskResolveCallback()
{
taskCompletionSource = new TaskCompletionSource<ResolveCallbackResult>();
taskCompletionSource = new TaskCompletionSource<ResolveCallbackResult>(TaskCreationOptions.RunContinuationsAsynchronously);
}
void IResolveCallback.OnResolveCompleted(CefErrorCode result, IList<string> 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;
+4 -5
View File
@@ -22,14 +22,14 @@ namespace CefSharp
/// </summary>
public TaskSetCookieCallback()
{
taskCompletionSource = new TaskCompletionSource<bool>();
taskCompletionSource = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
}
void ISetCookieCallback.OnComplete(bool success)
{
onComplete = true;
taskCompletionSource.TrySetResultAsync(success);
taskCompletionSource.TrySetResult(success);
}
/// <summary>
@@ -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;
+1 -1
View File
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net452</TargetFramework>
<TargetFramework>net462</TargetFramework>
<OutputType>Library</OutputType>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<SignAssembly>true</SignAssembly>
@@ -51,7 +51,7 @@ namespace CefSharp.WinForms
/// <summary>
/// Initial browser load task complection source
/// </summary>
private TaskCompletionSource<LoadUrlAsyncResponse> initialLoadTaskCompletionSource = new TaskCompletionSource<LoadUrlAsyncResponse>();
private TaskCompletionSource<LoadUrlAsyncResponse> initialLoadTaskCompletionSource = new TaskCompletionSource<LoadUrlAsyncResponse>(TaskCreationOptions.RunContinuationsAsynchronously);
/// <summary>
/// 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));
}
}
+2 -2
View File
@@ -33,7 +33,7 @@ namespace CefSharp.Internals
/// <returns>The unique id of the newly created pending task and the newly created <see cref="TaskCompletionSource{TResult}"/>.</returns>
public KeyValuePair<long, TaskCompletionSource<TResult>> CreatePendingTask(TimeSpan? timeout = null)
{
var taskCompletionSource = new TaskCompletionSource<TResult>();
var taskCompletionSource = new TaskCompletionSource<TResult>(TaskCreationOptions.RunContinuationsAsynchronously);
var id = Interlocked.Increment(ref lastId);
pendingTasks.TryAdd(id, taskCompletionSource);
@@ -54,7 +54,7 @@ namespace CefSharp.Internals
/// <returns>The unique id of the newly created pending task and the newly created <see cref="TaskCompletionSource{TResult}"/>.</returns>
public KeyValuePair<long, TaskCompletionSource<TResult>> CreateJavascriptCallbackPendingTask(long id, TimeSpan? timeout = null)
{
var taskCompletionSource = new TaskCompletionSource<TResult>();
var taskCompletionSource = new TaskCompletionSource<TResult>(TaskCreationOptions.RunContinuationsAsynchronously);
callbackPendingTasks.TryAdd(id, taskCompletionSource);
-102
View File
@@ -15,64 +15,6 @@ namespace CefSharp.Internals
/// </summary>
public static class TaskExtensions
{
/// <summary>Creates a new Task that mirrors the supplied task but that will be canceled after the specified timeout.</summary>
/// <typeparam name="TResult">Specifies the type of data contained in the task.</typeparam>
/// <param name="task">The task.</param>
/// <param name="timeout">The timeout.</param>
/// <returns>The new Task that may time out.</returns>
public static Task<TResult> WithTimeout<TResult>(this Task<TResult> task, TimeSpan timeout)
{
var result = new TaskCompletionSource<TResult>(task.AsyncState);
var timer = new Timer(state => ((TaskCompletionSource<TResult>)state).TrySetCanceled(), result, timeout, TimeSpan.FromMilliseconds(-1));
task.ContinueWith(t =>
{
timer.Dispose();
result.TrySetFromTask(t);
}, TaskContinuationOptions.ExecuteSynchronously);
return result.Task;
}
/// <summary>Attempts to transfer the result of a Task to the TaskCompletionSource.</summary>
/// <typeparam name="TResult">Specifies the type of the result.</typeparam>
/// <param name="resultSetter">The TaskCompletionSource.</param>
/// <param name="task">The task whose completion results should be transfered.</param>
/// <returns>Whether the transfer could be completed.</returns>
public static bool TrySetFromTask<TResult>(this TaskCompletionSource<TResult> resultSetter, Task task)
{
switch (task.Status)
{
case TaskStatus.RanToCompletion:
return resultSetter.TrySetResult(task is Task<TResult> ? ((Task<TResult>)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.");
}
}
/// <summary>Attempts to transfer the result of a Task to the TaskCompletionSource.</summary>
/// <typeparam name="TResult">Specifies the type of the result.</typeparam>
/// <param name="resultSetter">The TaskCompletionSource.</param>
/// <param name="task">The task whose completion results should be transfered.</param>
/// <returns>Whether the transfer could be completed.</returns>
public static bool TrySetFromTask<TResult>(this TaskCompletionSource<TResult> resultSetter, Task<TResult> task)
{
return TrySetFromTask(resultSetter, (Task)task);
}
public static Task<T> FromResult<T>(T value)
{
var tcs = new TaskCompletionSource<T>();
tcs.SetResult(value);
return tcs.Task;
}
public static TaskCompletionSource<TResult> WithTimeout<TResult>(this TaskCompletionSource<TResult> taskCompletionSource, TimeSpan timeout)
{
return WithTimeout(taskCompletionSource, timeout, null);
}
public static TaskCompletionSource<TResult> WithTimeout<TResult>(this TaskCompletionSource<TResult> taskCompletionSource, TimeSpan timeout, Action cancelled)
{
Timer timer = null;
@@ -91,49 +33,5 @@ namespace CefSharp.Internals
return taskCompletionSource;
}
/// <summary>
/// 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
/// </summary>
/// <typeparam name="TResult">Generic param</typeparam>
/// <param name="taskCompletionSource">tcs</param>
/// <param name="result">result</param>
public static void TrySetResultAsync<TResult>(this TaskCompletionSource<TResult> taskCompletionSource, TResult result)
{
Task.Factory.StartNew(delegate
{
taskCompletionSource.TrySetResult(result);
}, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default);
}
/// <summary>
/// Calls <see cref="TaskCompletionSource{TResult}.TrySetException(Exception)"/> 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
/// </summary>
/// <typeparam name="TResult">Generic param</typeparam>
/// <param name="taskCompletionSource">tcs</param>
/// <param name="ex">exception</param>
public static void TrySetExceptionAsync<TResult>(this TaskCompletionSource<TResult> taskCompletionSource, Exception ex)
{
Task.Factory.StartNew(delegate
{
taskCompletionSource.TrySetException(ex);
}, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default);
}
/// <summary>
/// Calls <see cref="TaskCompletionSource{TResult}.TrySetCanceled()"/> 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
/// </summary>
/// <typeparam name="TResult">Generic param</typeparam>
/// <param name="taskCompletionSource">tcs</param>
public static void TrySetCanceledAsync<TResult>(this TaskCompletionSource<TResult> taskCompletionSource)
{
Task.Factory.StartNew(delegate
{
taskCompletionSource.TrySetCanceled();
}, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default);
}
}
}
@@ -23,7 +23,7 @@ namespace CefSharp
/// <returns>List of objects that were bound</returns>
public static Task<IList<string>> EnsureObjectBoundAsync(this IWebBrowser browser, params string[] names)
{
var objBoundTasks = new TaskCompletionSource<IList<string>>();
var objBoundTasks = new TaskCompletionSource<IList<string>>(TaskCreationOptions.RunContinuationsAsynchronously);
EventHandler<JavascriptBindingMultipleCompleteEventArgs> 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)));
}
};
+3 -6
View File
@@ -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
/// </summary>
public TaskCookieVisitor()
{
taskCompletionSource = new TaskCompletionSource<List<Cookie>>();
taskCompletionSource = new TaskCompletionSource<List<Cookie>>(TaskCreationOptions.RunContinuationsAsynchronously);
list = new List<Cookie>();
}
@@ -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;
@@ -23,7 +23,7 @@ namespace CefSharp
/// </summary>
public TaskNavigationEntryVisitor()
{
taskCompletionSource = new TaskCompletionSource<List<NavigationEntry>>();
taskCompletionSource = new TaskCompletionSource<List<NavigationEntry>>(TaskCreationOptions.RunContinuationsAsynchronously);
list = new List<NavigationEntry>();
}
@@ -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;
+2 -2
View File
@@ -21,7 +21,7 @@ namespace CefSharp
/// </summary>
public TaskStringVisitor()
{
taskCompletionSource = new TaskCompletionSource<string>();
taskCompletionSource = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);
}
/// <summary>
@@ -30,7 +30,7 @@ namespace CefSharp
/// <param name="str">string (result of async execution)</param>
void IStringVisitor.Visit(string str)
{
taskCompletionSource.TrySetResultAsync(str);
taskCompletionSource.TrySetResult(str);
}
/// <summary>
+6 -6
View File
@@ -424,7 +424,7 @@ namespace CefSharp
throw new ArgumentNullException(nameof(url));
}
var tcs = new TaskCompletionSource<LoadUrlAsyncResponse>();
var tcs = new TaskCompletionSource<LoadUrlAsyncResponse>(TaskCreationOptions.RunContinuationsAsynchronously);
EventHandler<LoadErrorEventArgs> loadErrorHandler = null;
EventHandler<LoadingStateChangedEventArgs> 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<WaitForNavigationAsyncResponse>();
var tcs = new TaskCompletionSource<WaitForNavigationAsyncResponse>(TaskCreationOptions.RunContinuationsAsynchronously);
EventHandler<LoadErrorEventArgs> loadErrorHandler = null;
EventHandler<LoadingStateChangedEventArgs> 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));
}
};
+9 -9
View File
@@ -12,21 +12,21 @@
<tags>chrome browser</tags>
<copyright>Copyright © The CefSharp Authors</copyright>
<dependencies>
<group targetFramework=".NETFramework4.5.2">
<group targetFramework=".NETFramework4.6.2">
<dependency id="cef.redist.x86" version="[$RedistVersion$]" />
<dependency id="cef.redist.x64" version="[$RedistVersion$]" />
<dependency id="cef.redist.x64" version="[$RedistVersion$]" />
</group>
</dependencies>
</metadata>
<files>
<file src="..\CefSharp\bin\Release\CefSharp.dll" target="lib\net452"/>
<file src="..\CefSharp\bin\Release\CefSharp.xml" target="lib\net452"/>
<file src="..\CefSharp\bin\Release\CefSharp.pdb" target="lib\net452"/>
<file src="..\CefSharp.Core\bin\Release\CefSharp.Core.dll" target="lib\net452"/>
<file src="..\CefSharp.Core\bin\Release\CefSharp.Core.xml" target="lib\net452"/>
<file src="..\CefSharp.Core\bin\Release\CefSharp.Core.pdb" target="lib\net452"/>
<file src="..\CefSharp\bin\Release\CefSharp.dll" target="lib\net462"/>
<file src="..\CefSharp\bin\Release\CefSharp.xml" target="lib\net462"/>
<file src="..\CefSharp\bin\Release\CefSharp.pdb" target="lib\net462"/>
<file src="..\CefSharp.Core\bin\Release\CefSharp.Core.dll" target="lib\net462"/>
<file src="..\CefSharp.Core\bin\Release\CefSharp.Core.xml" target="lib\net462"/>
<file src="..\CefSharp.Core\bin\Release\CefSharp.Core.pdb" target="lib\net462"/>
<!-- Cannot put these inside lib\net452 etc, since there are both x86 and x64 versions which we must distinguish between. We
<!-- Cannot put these inside lib\net462 etc, since there are both x86 and x64 versions which we must distinguish between. We
solve this using a .targets file instead to copy them based on PlatformTarget -->
<!-- Common CefSharp stuff (shared between both WPF, Offscreen and WinForms) -->
+2 -2
View File
@@ -5,9 +5,9 @@
<CefSharpCommonBinaries32 Include="$(MSBuildThisFileDirectory)..\CefSharp\x86\*.*" />
<CefSharpCommonBinaries64 Include="$(MSBuildThisFileDirectory)..\CefSharp\x64\*.*" />
<CefSharpCommonBinariesAnyCPU Include="$(MSBuildThisFileDirectory)..\CefSharp\**\*.*" />
<CefSharpCommonManagedDlls Include="$(MSBuildThisFileDirectory)..\lib\net452\**\*.*" />
<CefSharpCommonManagedDlls Include="$(MSBuildThisFileDirectory)..\lib\net462\**\*.*" />
<!-- Just CefSharp.dlll -->
<CefSharpCommonManagedDll Include="$(MSBuildThisFileDirectory)..\lib\net452\CefSharp.dll" />
<CefSharpCommonManagedDll Include="$(MSBuildThisFileDirectory)..\lib\net462\CefSharp.dll" />
<CefSharpCommonTransform32 Include="$(MSBuildThisFileDirectory)..\build\app.config.x86.transform"/>
<CefSharpCommonTransform64 Include="$(MSBuildThisFileDirectory)..\build\app.config.x64.transform"/>
+3 -3
View File
@@ -397,7 +397,7 @@
<Message Importance="high" Text="Copying CefSharp Common x86 files from $(MSBuildThisFileDirectory)..\CefSharp\x86 to $(CefRedist32TargetDir)" />
<Copy SourceFiles="@(_CefSharpCommonBinaries32)" DestinationFiles="@(_CefSharpCommonBinaries32->'$(CefRedist32TargetDir)\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="true" />
<Message Importance="high" Text="Copying CefSharp.dll from $(MSBuildThisFileDirectory)..\lib\net452\CefSharp.dll to $(CefRedist32TargetDir)" />
<Message Importance="high" Text="Copying CefSharp.dll from $(MSBuildThisFileDirectory)..\lib\net462\CefSharp.dll to $(CefRedist32TargetDir)" />
<Copy SourceFiles="@(_CefSharpCommonManagedDll)" DestinationFiles="@(_CefSharpCommonManagedDll->'$(CefRedist32TargetDir)\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="true" />
</Target>
@@ -408,7 +408,7 @@
<Message Importance="high" Text="Copying CefSharp Common x64 files from $(MSBuildThisFileDirectory)..\CefSharp\x64 to $(CefRedist64TargetDir)" />
<Copy SourceFiles="@(_CefSharpCommonBinaries64)" DestinationFiles="@(_CefSharpCommonBinaries64->'$(CefRedist64TargetDir)\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="true" />
<Message Importance="high" Text="Copying CefSharp.dll from $(MSBuildThisFileDirectory)..\lib\net452\CefSharp.dll to $(CefRedist64TargetDir)" />
<Message Importance="high" Text="Copying CefSharp.dll from $(MSBuildThisFileDirectory)..\lib\net462\CefSharp.dll to $(CefRedist64TargetDir)" />
<Copy SourceFiles="@(_CefSharpCommonManagedDll)" DestinationFiles="@(_CefSharpCommonManagedDll->'$(CefRedist64TargetDir)\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="true" />
</Target>
@@ -427,7 +427,7 @@
<CefRedist64TargetDir Condition="'$(_CefSharpPlatformTarget)' == 'AnyCPU'">$(CefRedist64TargetDir)x64\</CefRedist64TargetDir>
</PropertyGroup>
<ItemGroup>
<_CefSharpCommonManagedDll Include="$(MSBuildThisFileDirectory)..\lib\net452\CefSharp.dll" />
<_CefSharpCommonManagedDll Include="$(MSBuildThisFileDirectory)..\lib\net462\CefSharp.dll" />
<_CefSharpCommonBinaries32 Include="$(MSBuildThisFileDirectory)..\CefSharp\x86\*.*" />
<_CefSharpCommonBinaries64 Include="$(MSBuildThisFileDirectory)..\CefSharp\x64\*.*" />
</ItemGroup>
+2 -9
View File
@@ -12,10 +12,7 @@
<tags>osr chrome browser chromium-embedded cefsharp</tags>
<copyright>Copyright © The CefSharp Authors</copyright>
<dependencies>
<group targetFramework=".NETFramework4.5.2">
<dependency id="CefSharp.Common" version="[$version$]" />
</group>
<group targetFramework=".NETFramework4.6.2">
<group targetFramework=".NETFramework4.6.2">
<dependency id="CefSharp.Common" version="[$version$]" />
</group>
</dependencies>
@@ -27,11 +24,7 @@
</releaseNotes>
</metadata>
<files>
<file src="..\CefSharp.OffScreen\bin\Release\net452\CefSharp.OffScreen.dll" target="lib\net452" />
<file src="..\CefSharp.OffScreen\bin\Release\net452\CefSharp.OffScreen.xml" target="lib\net452" />
<file src="..\CefSharp.OffScreen\bin\Release\net452\CefSharp.OffScreen.pdb" target="lib\net452" />
<file src="..\CefSharp.OffScreen\bin\Release\net462\CefSharp.OffScreen.dll" target="lib\net462" />
<file src="..\CefSharp.OffScreen\bin\Release\net462\CefSharp.OffScreen.dll" target="lib\net462" />
<file src="..\CefSharp.OffScreen\bin\Release\net462\CefSharp.OffScreen.xml" target="lib\net462" />
<file src="..\CefSharp.OffScreen\bin\Release\net462\CefSharp.OffScreen.pdb" target="lib\net462" />
+2 -9
View File
@@ -12,10 +12,7 @@
<tags>winforms chrome browser chromium-embedded cefsharp</tags>
<copyright>Copyright © The CefSharp Authors</copyright>
<dependencies>
<group targetFramework=".NETFramework4.5.2">
<dependency id="CefSharp.Common" version="[$version$]" />
</group>
<group targetFramework=".NETFramework4.6.2">
<group targetFramework=".NETFramework4.6.2">
<dependency id="CefSharp.Common" version="[$version$]" />
</group>
</dependencies>
@@ -27,11 +24,7 @@
</releaseNotes>
</metadata>
<files>
<file src="..\CefSharp.WinForms\bin\Release\net452\CefSharp.WinForms.dll" target="lib\net452" />
<file src="..\CefSharp.WinForms\bin\Release\net452\CefSharp.WinForms.xml" target="lib\net452" />
<file src="..\CefSharp.WinForms\bin\Release\net452\CefSharp.WinForms.pdb" target="lib\net452" />
<file src="..\CefSharp.WinForms\bin\Release\net462\CefSharp.WinForms.dll" target="lib\net462" />
<file src="..\CefSharp.WinForms\bin\Release\net462\CefSharp.WinForms.dll" target="lib\net462" />
<file src="..\CefSharp.WinForms\bin\Release\net462\CefSharp.WinForms.xml" target="lib\net462" />
<file src="..\CefSharp.WinForms\bin\Release\net462\CefSharp.WinForms.pdb" target="lib\net462" />
+2 -9
View File
@@ -12,10 +12,7 @@
<tags>wpf chrome browser chromium-embedded cefsharp</tags>
<copyright>Copyright © The CefSharp Authors</copyright>
<dependencies>
<group targetFramework=".NETFramework4.5.2">
<dependency id="CefSharp.Common" version="[$version$]" />
</group>
<group targetFramework=".NETFramework4.6.2">
<group targetFramework=".NETFramework4.6.2">
<dependency id="CefSharp.Common" version="[$version$]" />
</group>
</dependencies>
@@ -27,11 +24,7 @@
</releaseNotes>
</metadata>
<files>
<file src="..\CefSharp.Wpf\bin\Release\net452\CefSharp.Wpf.dll" target="lib\net452" />
<file src="..\CefSharp.Wpf\bin\Release\net452\CefSharp.Wpf.xml" target="lib\net452" />
<file src="..\CefSharp.Wpf\bin\Release\net452\CefSharp.Wpf.pdb" target="lib\net452" />
<file src="..\CefSharp.Wpf\bin\Release\net462\CefSharp.Wpf.dll" target="lib\net462" />
<file src="..\CefSharp.Wpf\bin\Release\net462\CefSharp.Wpf.dll" target="lib\net462" />
<file src="..\CefSharp.Wpf\bin\Release\net462\CefSharp.Wpf.xml" target="lib\net462" />
<file src="..\CefSharp.Wpf\bin\Release\net462\CefSharp.Wpf.pdb" target="lib\net462" />
+2 -2
View File
@@ -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)
+1 -1
View File
@@ -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 |