CefSharp v62 modification method (. net4.0 supported), cefsharpv62
Excuse me, I haven't been on the blog site for a long time, and my account is gone. Apply for a new one.
Cesharp v62 adopts the latest Cef 62 kernel and supports the latest Grid layout. because cefsharp is officially used. net4.5.2 development. what should I do. I can only use. net4.0. no way. Use the source code to modify the compatibility.
Carefully analyze the source code and find that:
1. net4.5.2 introduced the async/await keyword. In fact, the overseas experts have already released the source code. We will introduce the Code directly into the cefsharp project. We can directly use async/await in 4.0;
2. net4.5 extends the task api. You only need to implement the corresponding api in. net4.0.
3. Many GetTypeInfo extension methods are used in the source code. The returned Type is typeinfo. You can delete GetTypeInfo without worrying about it. You can call the Type directly.
4. for extension of the Task static method, you need to modify the call method of the static method.
The above is the key point. The following is the source code:
The source code is for: async/await support:
namespace System.Threading.Tasks{ public static class TaskEx { public static TaskAwaiter GetAwaiter(this Task task) { return new TaskAwaiter(task); } public static TaskAwaiter<T> GetAwaiter<T>(this Task<T> task) { return new TaskAwaiter<T>(task); } } public struct TaskAwaiter : INotifyCompletion { readonly Task task; internal TaskAwaiter(Task task) { this.task = task; } internal static TaskScheduler TaskScheduler { get { if (SynchronizationContext.Current == null) return TaskScheduler.Default; else return TaskScheduler.FromCurrentSynchronizationContext(); } } public bool IsCompleted { get { return task.IsCompleted; } } public void OnCompleted(Action continuation) { this.task.ContinueWith( delegate (Task task) { continuation(); }, TaskAwaiter.TaskScheduler); } public void GetResult() { try { task.Wait(); } catch (AggregateException ex) { throw ex.InnerExceptions[0]; } } } public struct TaskAwaiter<T> : INotifyCompletion { readonly Task<T> task; internal TaskAwaiter(Task<T> task) { this.task = task; } public bool IsCompleted { get { return task.IsCompleted; } } public void OnCompleted(Action continuation) { this.task.ContinueWith( delegate (Task<T> task) { continuation(); }, TaskAwaiter.TaskScheduler); } public T GetResult() { try { return task.Result; } catch (AggregateException ex) { throw ex.InnerExceptions[0]; } } }}namespace System.Runtime.CompilerServices{ public interface INotifyCompletion { void OnCompleted(Action continuation); } public interface ICriticalNotifyCompletion : INotifyCompletion { [SecurityCritical] void UnsafeOnCompleted(Action continuation); } public interface IAsyncStateMachine { void MoveNext(); void SetStateMachine(IAsyncStateMachine stateMachine); } public struct AsyncVoidMethodBuilder { public static AsyncVoidMethodBuilder Create() { return new AsyncVoidMethodBuilder(); } public void SetException(Exception exception) { throw exception; } public void SetResult() { } public void SetStateMachine(IAsyncStateMachine stateMachine) { // Should not get called as we don't implement the optimization that this method is used for. throw new NotImplementedException(); } public void Start<TStateMachine>(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine { stateMachine.MoveNext(); } public void AwaitOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine) where TAwaiter : INotifyCompletion where TStateMachine : IAsyncStateMachine { awaiter.OnCompleted(stateMachine.MoveNext); } public void AwaitUnsafeOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine) where TAwaiter : ICriticalNotifyCompletion where TStateMachine : IAsyncStateMachine { awaiter.OnCompleted(stateMachine.MoveNext); } } public struct AsyncTaskMethodBuilder { TaskCompletionSource<object> tcs; public Task Task { get { return tcs.Task; } } public static AsyncTaskMethodBuilder Create() { AsyncTaskMethodBuilder b; b.tcs = new TaskCompletionSource<object>(); return b; } public void Start<TStateMachine>(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine { stateMachine.MoveNext(); } public void SetStateMachine(IAsyncStateMachine stateMachine) { // Should not get called as we don't implement the optimization that this method is used for. throw new NotImplementedException(); } public void AwaitOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine) where TAwaiter : INotifyCompletion where TStateMachine : IAsyncStateMachine { awaiter.OnCompleted(stateMachine.MoveNext); } public void AwaitUnsafeOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine) where TAwaiter : ICriticalNotifyCompletion where TStateMachine : IAsyncStateMachine { awaiter.OnCompleted(stateMachine.MoveNext); } public void SetResult() { tcs.SetResult(null); } public void SetException(Exception exception) { tcs.SetException(exception); } } public struct AsyncTaskMethodBuilder<T> { TaskCompletionSource<T> tcs; public Task<T> Task { get { return tcs.Task; } } public static AsyncTaskMethodBuilder<T> Create() { AsyncTaskMethodBuilder<T> b; b.tcs = new TaskCompletionSource<T>(); return b; } public void Start<TStateMachine>(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine { stateMachine.MoveNext(); } public void SetStateMachine(IAsyncStateMachine stateMachine) { // Should not get called as we don't implement the optimization that this method is used for. throw new NotImplementedException(); } public void AwaitOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine) where TAwaiter : INotifyCompletion where TStateMachine : IAsyncStateMachine { awaiter.OnCompleted(stateMachine.MoveNext); } public void AwaitUnsafeOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine) where TAwaiter : ICriticalNotifyCompletion where TStateMachine : IAsyncStateMachine { AwaitOnCompleted(ref awaiter, ref stateMachine); } public void SetResult(T result) { tcs.SetResult(result); } public void SetException(Exception exception) { tcs.SetException(exception); } }}
This section is an extension of the Task.
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading;using System.Threading.Tasks;namespace CefSharp{ public class TaskEx { public static Task<T> FromResult<T>(T t) { return Task.Factory.StartNew<T>(() => t); } public static Task Run(Action action) { var tcs = new TaskCompletionSource<object>(); new Thread(() => { try { action(); tcs.SetResult(null); } catch (Exception ex) { tcs.SetException(ex); } }) { IsBackground = true }.Start(); return tcs.Task; } public static Task<TResult> Run<TResult>(Func<TResult> function) { var tcs = new TaskCompletionSource<TResult>(); new Thread(() => { try { tcs.SetResult(function()); } catch (Exception ex) { tcs.SetException(ex); } }) { IsBackground = true }.Start(); return tcs.Task; } public static Task Delay(int milliseconds) { var tcs = new TaskCompletionSource<object>(); var timer = new System.Timers.Timer(milliseconds) { AutoReset = false }; timer.Elapsed += delegate { timer.Dispose(); tcs.SetResult(null); }; timer.Start(); return tcs.Task; } }}
Replace Task. Run in C # With TaskEx. Run, and Task. Delay with TaskEx. Delay.
If the error GetTypeInfo is reported, it is OK to delete it.
The above CefSharp v62 modification method (supports. net4.0) is all the content shared by Alibaba Cloud xiaobian. I hope you can give us a reference and support for the customer's house.