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);
+ }
+ }
}
}