using System; using System.Collections.Generic; namespace Terminal.Gui; /// /// The execution state for a view. /// public class RunState : IDisposable { /// /// Initializes a new class. /// /// public RunState (Toplevel view) { Toplevel = view; } /// /// The belonging to this . /// public Toplevel Toplevel { get; internal set; } #if DEBUG_IDISPOSABLE /// /// For debug (see DEBUG_IDISPOSABLE define) purposes to verify objects are being disposed properly /// public bool WasDisposed = false; /// /// For debug (see DEBUG_IDISPOSABLE define) purposes to verify objects are being disposed properly /// public int DisposedCount = 0; /// /// For debug (see DEBUG_IDISPOSABLE define) purposes; the runstate instances that have been created /// public static List Instances = new List (); /// /// Creates a new RunState object. /// public RunState () { Instances.Add (this); } #endif /// /// Releases all resource used by the object. /// /// /// Call when you are finished using the . /// /// /// method leaves the in an unusable state. After /// calling , you must release all references to the /// so the garbage collector can reclaim the memory that the /// was occupying. /// public void Dispose () { Dispose (true); GC.SuppressFinalize (this); #if DEBUG_IDISPOSABLE WasDisposed = true; #endif } /// /// Releases all resource used by the object. /// /// If set to we are disposing and should dispose held objects. protected virtual void Dispose (bool disposing) { if (Toplevel != null && disposing) { throw new InvalidOperationException ("You must clean up (Dispose) the Toplevel before calling Application.RunState.Dispose"); } } }