From 138199e8114e55cafeefefe57afd4e6153412574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexei=20Ag=C3=BCero=20Alba?= Date: Mon, 5 Dec 2022 17:12:53 -0500 Subject: [PATCH] Correctly implement Dispose pattern in FormBase for use on derived classes --- TelegramBotBase/Base/FormBase.cs | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/TelegramBotBase/Base/FormBase.cs b/TelegramBotBase/Base/FormBase.cs index 291e733..d3c2cba 100644 --- a/TelegramBotBase/Base/FormBase.cs +++ b/TelegramBotBase/Base/FormBase.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.ComponentModel; using System.Linq; -using System.Text; using System.Threading.Tasks; using TelegramBotBase.Args; using TelegramBotBase.Base; @@ -17,7 +16,6 @@ namespace TelegramBotBase.Form /// public class FormBase : IDisposable { - public NavigationController NavigationController { get; set; } public DeviceSession Device { get; set; } @@ -432,14 +430,29 @@ namespace TelegramBotBase.Form } } + protected virtual void Dispose(bool disposing) + { + if (this.IsDisposed) + { + return; + } + + if (disposing) + { + this.Client = null; + this.Device = null; + } + + this.IsDisposed = true; + } + /// /// Cleanup /// public void Dispose() { - this.Client = null; - this.Device = null; - this.IsDisposed = true; + Dispose(true); + GC.SuppressFinalize(this); } } }