ICompletionCallback now implements IDisposable and the CefCompletionCallbackAdapter disposes of the instance when it itself is disposed of.

This commit is contained in:
amaitland
2017-02-09 13:15:55 +10:00
parent fe9d6a45a9
commit 4d697e00c8
3 changed files with 17 additions and 2 deletions
@@ -22,6 +22,7 @@ namespace CefSharp
~CefCompletionCallbackAdapter()
{
delete _handler;
_handler = nullptr;
}
+2 -1
View File
@@ -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
{
/// <summary>
/// Generic callback interface used for asynchronous completion.
/// </summary>
public interface ICompletionCallback
public interface ICompletionCallback : IDisposable
{
/// <summary>
/// Method that will be called once the task is complete.
+14 -1
View File
@@ -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<bool>();
}
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);
}
}
}
}