From 4d697e00c8ec83739adb83fc97375ffb19db71f4 Mon Sep 17 00:00:00 2001 From: amaitland Date: Thu, 9 Feb 2017 13:15:55 +1000 Subject: [PATCH] ICompletionCallback now implements IDisposable and the CefCompletionCallbackAdapter disposes of the instance when it itself is disposed of. --- .../Internals/CefCompletionCallbackAdapter.h | 1 + CefSharp/ICompletionCallback.cs | 3 ++- CefSharp/TaskCompletionHandler.cs | 15 ++++++++++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/CefSharp.Core/Internals/CefCompletionCallbackAdapter.h b/CefSharp.Core/Internals/CefCompletionCallbackAdapter.h index 4c1340e06..cb01e0501 100644 --- a/CefSharp.Core/Internals/CefCompletionCallbackAdapter.h +++ b/CefSharp.Core/Internals/CefCompletionCallbackAdapter.h @@ -22,6 +22,7 @@ namespace CefSharp ~CefCompletionCallbackAdapter() { + delete _handler; _handler = nullptr; } diff --git a/CefSharp/ICompletionCallback.cs b/CefSharp/ICompletionCallback.cs index 98588612d..906dcad87 100644 --- a/CefSharp/ICompletionCallback.cs +++ b/CefSharp/ICompletionCallback.cs @@ -2,12 +2,13 @@ // // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. +using System; namespace CefSharp { /// /// Generic callback interface used for asynchronous completion. /// - public interface ICompletionCallback + public interface ICompletionCallback : IDisposable { /// /// Method that will be called once the task is complete. diff --git a/CefSharp/TaskCompletionHandler.cs b/CefSharp/TaskCompletionHandler.cs index 8d3e0c5de..86132916b 100644 --- a/CefSharp/TaskCompletionHandler.cs +++ b/CefSharp/TaskCompletionHandler.cs @@ -2,6 +2,7 @@ // // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. +using System; using System.Threading.Tasks; using CefSharp.Internals; @@ -16,7 +17,7 @@ namespace CefSharp taskCompletionSource = new TaskCompletionSource(); } - public void OnComplete() + void ICompletionCallback.OnComplete() { taskCompletionSource.TrySetResultAsync(true); } @@ -25,5 +26,17 @@ namespace CefSharp { get { return taskCompletionSource.Task; } } + + void IDisposable.Dispose() + { + var task = taskCompletionSource.Task; + + //If the Task hasn't completed and this is being disposed then + //set the TCS to false + if(task.IsCompleted == false) + { + taskCompletionSource.TrySetResultAsync(false); + } + } } }