/// <summary> /// Cleans up either unmanaged resources or managed and unmanaged resources. /// </summary> /// <remarks> /// <para> /// If disposing equals true, the method has been called directly or indirectly by a user's /// code. Managed and unmanaged resources can be disposed. /// </para> /// <para> /// If disposing equals false, the method has been called by the runtime from inside the /// finalizer and you should not reference other objects. Only unmanaged resources can /// be disposed. /// </para> /// </remarks> /// <param name="disposing">Was Dispose called manually?</param> private static void Dispose(bool disposing) { if(!isDisposed) { // Check To See If Dispose Has Already Been Called if(disposing) { // If disposing Equals true, Dispose All Managed And Unmanaged Resources if(timer != null) { timer.Dispose(); } if(form != null) { form.Close(); } if(view != null) { view.Dispose(); } if(model != null) { model.Dispose(); } } // Release Any Unmanaged Resources Here, If disposing Was false, Only The Following Code Is Executed isRunning = false; timer = null; form = null; view = null; model = null; } isDisposed = true; // Mark As disposed }
private bool isDisposed = false; // Has Disposed Been Called For This View? #endregion Fields #region Constructors /// <summary> /// Creates a <see cref="View" /> displaying the supplied, inherited <see cref="Model" />. /// </summary> /// <param name="inheritedModel"> /// The <see cref="Model" /> to be displayed by this view. /// </param> public View(Model inheritedModel) { model = inheritedModel; }
/// <summary> /// Runs the supplied <see cref="Model" /> as a Windows Forms application. /// </summary> /// <param name="inheritedModel"> /// The inherited <see cref="Model" /> to run as an application. /// </param> public static void Run(Model inheritedModel) { model = inheritedModel; // Set The Local Model To The Passed In Model model.Setup(); // Run Any One-Time-Only Setup Defined By The Model CreateForm(); // Create An Initial Form GC.Collect(); // Force A Collection MainLoop(); // Runs The Main Application Loop Dispose(); // Cleans Up When The Application Ends Application.Exit(); // Exit }