예제 #1
0
        /// <inheritdoc />
        public async ValueTask DisposeAsync()
        {
            lock (synchronizationLock)
            {
                if (disposed)
                {
                    return;
                }
                disposed = true;
            }

            logger.LogTrace("Disposing...");
            if (!released)
            {
                process.Terminate();
                byondLock.Dispose();
            }

            process.Dispose();
            bridgeRegistration?.Dispose();
            reattachInformation.Dmb?.Dispose();             // will be null when released
            chatTrackingContext.Dispose();
            reattachTopicCts.Dispose();

            if (!released)
            {
                // finish the async callback
                await Lifetime.ConfigureAwait(false);
            }
        }
        /// <summary>
        /// Implements the <see cref="IDisposable"/> pattern
        /// </summary>
        /// <param name="disposing">If this function was NOT called by the finalizer</param>
        void Dispose(bool disposing)
        {
            lock (synchronizationLock)
            {
                if (disposed)
                {
                    return;
                }
                if (disposing)
                {
                    if (!released)
                    {
                        process.Terminate();
                        byondLock.Dispose();
                    }

                    process.Dispose();
                    bridgeRegistration.Dispose();
                    Dmb?.Dispose();                     // will be null when released
                    chatTrackingContext.Dispose();
                    reattachTopicCts.Dispose();
                    disposed = true;
                }
                else
                {
                    if (logger != null)
                    {
                        logger.LogError("Being disposed via finalizer!");
                    }
                    if (!released)
                    {
                        if (process != null)
                        {
                            process.Terminate();
                        }
                        else if (logger != null)
                        {
                            logger.LogCritical("Unable to terminate active DreamDaemon session due to finalizer ordering!");
                        }
                    }
                }
            }
        }