/// <summary> /// Function to clean up after an application exits. /// </summary> private static void CleanUp() { IsRunning = false; // Attach assembly resolving to deal with issues when loading assemblies with designers/type converters. AppDomain.CurrentDomain.AssemblyResolve -= ResolveAssembly; // Remove quit handlers. Application.ApplicationExit -= Application_ApplicationExit; Application.ThreadExit -= Application_ThreadExit; if (ApplicationIdleLoopMethod != null) { Application.Idle -= Application_Idle; Log.Print("Application loop stopped.", LoggingLevel.Simple); } if (_trackedObjects != null) { _trackedObjects.ReleaseAll(); } PlugIns.UnloadAll(); // Reset the low resolution timer period on application end. if (GorgonTimer.UsingLowResTimers) { GorgonTimer.ResetLowResTimerPeriod(); } Log.Print("Shutting down.", LoggingLevel.All); // Destroy log. if (!Log.IsClosed) { Log.Close(); } }
/// <summary> /// Releases unmanaged and - optionally - managed resources. /// </summary> /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> private void Dispose(bool disposing) { if (_disposed) { return; } if (disposing) { Gorgon.Log.Print("Gorgon Graphics Context shutting down...", LoggingLevel.Simple); if (!IsDeferred) { _trackedObjects.ReleaseAll(); } else { Context.ClearState(); } DestroyInterfaces(); // Only clean up the context if the context is deferred. if (IsDeferred) { if (_commands != null) { // Release any outstanding command lists. while (_commands.Count > 0) { ReleaseCommands(_commands[_commands.Count - 1]); } } if (Context != null) { Context.Flush(); Context.Dispose(); } Context = null; // Remove us from object tracking. ImmediateContext.RemoveTrackedObject(this); } else { Gorgon.Log.Print("Removing D3D11 Device object...", LoggingLevel.Verbose); // Destroy the video device interface. if (D3DDevice != null) { D3DDevice.Dispose(); D3DDevice = null; } if (Adapter != null) { Adapter.Dispose(); Adapter = null; } if (GIFactory != null) { GIFactory.Dispose(); GIFactory = null; } if (VideoDevice != null) { VideoDevice.Graphics = null; } Gorgon.Log.Print("Removing DXGI factory interface...", LoggingLevel.Verbose); if (GIFactory != null) { GIFactory.Dispose(); GIFactory = null; } // Remove us from the object tracker. Gorgon.RemoveTrackedObject(this); } Gorgon.Log.Print("Gorgon Graphics Context shut down successfully", LoggingLevel.Simple); } _disposed = true; }