mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-06 04:00:07 +00:00
ICompletionCallback now implements IDisposable and the CefCompletionCallbackAdapter disposes of the instance when it itself is disposed of.
This commit is contained in:
@@ -22,6 +22,7 @@ namespace CefSharp
|
||||
|
||||
~CefCompletionCallbackAdapter()
|
||||
{
|
||||
delete _handler;
|
||||
_handler = nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user