@ -111,7 +111,7 @@ namespace Emby.Server.Implementations
/// <summary>
/// Class CompositionRoot.
/// </summary>
public abstract class ApplicationHost : IServerApplicationHost , I Disposable
public abstract class ApplicationHost : IServerApplicationHost , I AsyncDisposable, I Disposable
{
/// <summary>
/// The environment variable prefixes to log at server startup.
@ -1232,5 +1232,49 @@ namespace Emby.Server.Implementations
_disposed = true ;
}
public async ValueTask DisposeAsync ( )
{
await DisposeAsyncCore ( ) . ConfigureAwait ( false ) ;
Dispose ( false ) ;
GC . SuppressFinalize ( this ) ;
}
/// <summary>
/// Used to perform asynchronous cleanup of managed resources or for cascading calls to <see cref="DisposeAsync"/>.
/// </summary>
/// <returns>A ValueTask.</returns>
protected virtual async ValueTask DisposeAsyncCore ( )
{
var type = GetType ( ) ;
Logger . LogInformation ( "Disposing {Type}" , type . Name ) ;
foreach ( var ( part , _ ) in _disposableParts )
{
var partType = part . GetType ( ) ;
if ( partType = = type )
{
continue ;
}
Logger . LogInformation ( "Disposing {Type}" , partType . Name ) ;
try
{
part . Dispose ( ) ;
}
catch ( Exception ex )
{
Logger . LogError ( ex , "Error disposing {Type}" , partType . Name ) ;
}
}
// used for closing websockets
foreach ( var session in _sessionManager . Sessions )
{
await session . DisposeAsync ( ) . ConfigureAwait ( false ) ;
}
}
}
}