Skip to content

Commit

Permalink
Upgrade to .Net 4.6.2 (#4482)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
amaitland authored Jun 9, 2023
1 parent 2521052 commit 1def8a7
Show file tree
Hide file tree
Showing 36 changed files with 96 additions and 240 deletions.
Original file line number Diff line number Diff line change
@@ -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')" />
Expand Down Expand Up @@ -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" />
Expand Down Expand Up @@ -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>
Original file line number Diff line number Diff line change
@@ -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>
Expand Down
2 changes: 1 addition & 1 deletion CefSharp.BrowserSubprocess/app.config
Original file line number Diff line number Diff line change
@@ -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>
6 changes: 3 additions & 3 deletions CefSharp.Core.Runtime/CefSharp.Core.Runtime.vcxproj
Original file line number Diff line number Diff line change
@@ -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')" />
Expand Down Expand Up @@ -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" />
Expand Down Expand Up @@ -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>
5 changes: 1 addition & 4 deletions CefSharp.Core.Runtime/Internals/CefBrowserHostWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
2 changes: 1 addition & 1 deletion CefSharp.Core.Runtime/Internals/ClientAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion CefSharp.Core/CefSharp.Core.csproj
Original file line number Diff line number Diff line change
@@ -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>
Expand Down
8 changes: 4 additions & 4 deletions CefSharp.Core/DevTools/DevToolsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public Task<T> ExecuteDevToolsMethodAsync<T>(string method, IDictionary<string,
throw new ObjectDisposedException(nameof(IBrowser));
}

var taskCompletionSource = new TaskCompletionSource<T>();
var taskCompletionSource = new TaskCompletionSource<T>(TaskCreationOptions.RunContinuationsAsynchronously);

var methodResultContext = new DevToolsMethodResponseContext(
type: typeof(T),
Expand Down Expand Up @@ -332,7 +332,7 @@ void IDevToolsMessageObserver.OnDevToolsMethodResult(IBrowser browser, int messa
/// <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>
Expand All @@ -359,7 +359,7 @@ private static T DeserializeJsonEvent<T>(string eventName, Stream stream) where
/// <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>
Expand All @@ -372,7 +372,7 @@ private static T DeserializeJson<T>(Stream stream)
/// <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>
Expand Down
10 changes: 5 additions & 5 deletions CefSharp.Core/WebBrowserExtensionsEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ public static Task<NavigationEntry> GetVisibleNavigationEntryAsync(this IChromiu
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;
Expand Down Expand Up @@ -107,7 +107,7 @@ public static Task<byte[]> DownloadUrlAsync(this IFrame frame, string url)
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
Expand All @@ -129,11 +129,11 @@ public static Task<byte[]> DownloadUrlAsync(this IFrame frame, string url)
{
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();
Expand Down
2 changes: 1 addition & 1 deletion CefSharp.OffScreen/CefSharp.OffScreen.csproj
Original file line number Diff line number Diff line change
@@ -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>
Expand Down
18 changes: 8 additions & 10 deletions CefSharp.OffScreen/ChromiumWebBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -389,11 +389,11 @@ public void CreateBrowser(IWindowInfo windowInfo = null, IBrowserSettings browse
/// </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
Expand All @@ -402,7 +402,7 @@ public Task<IBrowser> CreateBrowserAsync(IWindowInfo windowInfo = null, IBrowser
}
catch(Exception ex)
{
tcs.TrySetExceptionAsync(ex);
tcs.TrySetException(ex);
}

return tcs.Task;
Expand Down Expand Up @@ -520,7 +520,7 @@ public Task<Bitmap> ScreenshotAsync(bool ignoreExistingScreenshot = false, Popup
// 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)
{
Expand All @@ -539,15 +539,15 @@ public Task<Bitmap> ScreenshotAsync(bool ignoreExistingScreenshot = false, Popup
}
else
{
completionSource.TrySetResultAsync(ScreenshotOrNull(blend));
completionSource.TrySetResult(ScreenshotOrNull(blend));
}
};

AfterPaint += afterPaint;
}
else
{
completionSource.TrySetResultAsync(screenshot);
completionSource.TrySetResult(screenshot);
}

return completionSource.Task;
Expand Down Expand Up @@ -640,7 +640,7 @@ public Task ResizeAsync(int width, int height, float? deviceScaleFactor = null)
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) =>
Expand All @@ -649,7 +649,7 @@ public Task ResizeAsync(int width, int height, float? deviceScaleFactor = null)
{
AfterPaint -= handler;

tcs.TrySetResultAsync(true);
tcs.TrySetResult(true);
}
};

Expand Down Expand Up @@ -692,7 +692,6 @@ public void Load(string url)
}
}

#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
Expand Down Expand Up @@ -750,7 +749,6 @@ public async Task WaitForRenderIdleAsync(int idleTimeInMs = 500, TimeSpan? timeo
throw;
}
}
#endif

/// <summary>
/// The javascript object repository, one repository per ChromiumWebBrowser instance.
Expand Down
2 changes: 1 addition & 1 deletion CefSharp.WinForms/CefSharp.WinForms.csproj
Original file line number Diff line number Diff line change
@@ -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>
Expand Down
2 changes: 1 addition & 1 deletion CefSharp.Wpf/CefSharp.Wpf.csproj
Original file line number Diff line number Diff line change
@@ -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>
Expand Down
6 changes: 0 additions & 6 deletions CefSharp.Wpf/ChromiumWebBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1776,15 +1776,13 @@ private void PresentationSourceChangedHandler(object sender, SourceChangedEventA
}
}

#if NETCOREAPP || NET462
/// <inheritdoc/>
protected override void OnDpiChanged(DpiScale oldDpi, DpiScale newDpi)
{
NotifyDpiChange((float)newDpi.DpiScaleX);

base.OnDpiChanged(oldDpi, newDpi);
}
#endif

private void OnWindowStateChanged(object sender, EventArgs e)
{
Expand Down Expand Up @@ -2638,8 +2636,6 @@ private void ZoomReset()
/// 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
Expand Down Expand Up @@ -2680,7 +2676,6 @@ public virtual void NotifyDpiChange(float newDpi)
}
}

#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
Expand Down Expand Up @@ -2738,7 +2733,6 @@ public async Task WaitForRenderIdleAsync(int idleTimeInMs = 500, TimeSpan? timeo
throw;
}
}
#endif

/// <summary>
/// Legacy keyboard handler uses WindowProc callback interceptor to forward keypress events
Expand Down
10 changes: 4 additions & 6 deletions CefSharp/Callback/TaskCompletionCallback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

using System;
using System.Threading.Tasks;
using CefSharp.Internals;

namespace CefSharp
{
Expand All @@ -22,14 +21,14 @@ public sealed class TaskCompletionCallback : ICompletionCallback
/// </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>
Expand All @@ -50,11 +49,10 @@ void IDisposable.Dispose()
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;
Expand Down
9 changes: 4 additions & 5 deletions CefSharp/Callback/TaskDeleteCookiesCallback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ public class TaskDeleteCookiesCallback : IDeleteCookiesCallback
/// </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>
Expand All @@ -54,11 +54,10 @@ void IDisposable.Dispose()
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;
Expand Down
Loading

0 comments on commit 1def8a7

Please sign in to comment.