Core - IAudioHandler now implements IDisposable

IAudioHandler.Dispose is called when the ChromiumWebBrowser instance is being Disposed.

This is a breaking change.

Resolves #3598
This commit is contained in:
Alex Maitland
2021-06-04 15:49:52 +10:00
parent e1ac768a42
commit a6ff42ee6f
6 changed files with 37 additions and 5 deletions
+1 -1
View File
@@ -275,7 +275,7 @@ namespace CefSharp.OffScreen
// Release reference to handlers, except LifeSpanHandler which is done after Disposing
// ManagedCefBrowserAdapter otherwise the ILifeSpanHandler.DoClose will not be invoked.
this.SetHandlersToNullExceptLifeSpan();
FreeHandlersExceptLifeSpan();
browser = null;
+1 -1
View File
@@ -407,7 +407,7 @@ namespace CefSharp.WinForms
// Release reference to handlers, except LifeSpanHandler which is done after Disposing
// ManagedCefBrowserAdapter otherwise the ILifeSpanHandler.DoClose will not be invoked.
this.SetHandlersToNullExceptLifeSpan();
FreeHandlersExceptLifeSpan();
browser = null;
+1 -1
View File
@@ -637,7 +637,7 @@ namespace CefSharp.Wpf
// Release reference to handlers, except LifeSpanHandler which is done after Disposing
// ManagedCefBrowserAdapter otherwise the ILifeSpanHandler.DoClose will not be invoked.
this.SetHandlersToNullExceptLifeSpan();
this.FreeHandlersExceptLifeSpan();
browser = null;
+27
View File
@@ -13,6 +13,17 @@ namespace CefSharp.Handler
/// </summary>
public class AudioHandler : IAudioHandler
{
private bool isDisposed;
/// <summary>
/// Gets a value indicating this <see cref="AudioHandler"/> instance
/// has been disposed.
/// </summary>
public bool IsDisposed
{
get { return isDisposed; }
}
/// <inheritdoc/>
bool IAudioHandler.GetAudioParameters(IWebBrowser chromiumWebBrowser, IBrowser browser, ref AudioParameters parameters)
{
@@ -117,5 +128,21 @@ namespace CefSharp.Handler
{
}
/// <summary>
/// Releases unmanaged and managed resources
/// </summary>
/// <param name="disposing"><see langword="true" /> to release both managed and unmanaged resources; <see langword="false" /> to release only unmanaged resources.</param>
protected virtual void Dispose(bool disposing)
{
isDisposed = true;
}
/// <inheritdoc />
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
}
+1 -1
View File
@@ -11,7 +11,7 @@ namespace CefSharp
/// Implement this interface to handle audio events
/// All methods will be called on the CEF UI thread
/// </summary>
public interface IAudioHandler
public interface IAudioHandler : IDisposable
{
/// <summary>
/// Called on the CEF UI thread to allow configuration of audio stream parameters.
@@ -326,8 +326,13 @@ namespace CefSharp.WinForms
partial void OnAfterBrowserCreated(IBrowser browser);
private void SetHandlersToNullExceptLifeSpan()
/// <summary>
/// Sets the handler references to null.
/// Where required also calls Dispose().
/// </summary>
private void FreeHandlersExceptLifeSpan()
{
AudioHandler?.Dispose();
AudioHandler = null;
DialogHandler = null;
FindHandler = null;