public void Dispose() { engine = null; GC.Collect(); GC.WaitForPendingFinalizers(); if (engineLoader != null) { engineLoader.ExplicitlyUnload(); engineLoader = null; GC.Collect(); GC.WaitForPendingFinalizers(); } if (!process.WaitForExit(5000)) { try { process.Kill(); } catch (InvalidOperationException) { // The process could exit between a decision to kill it and this code // Skip this error } } process.Dispose(); process = null; }
public void Dispose() { foreach (FineReaderDocument doc in documents.Values) { try { doc.Document.Close(); } catch { } } try { #if DEBUG long memorySizeBefore = GC.GetTotalMemory(false); #endif lock (syncRoot) { engine = null; instance = null; engineLoader.ExplicitlyUnload(); engineLoader = null; GC.Collect(); System.Threading.Thread.Sleep(1); GC.WaitForPendingFinalizers(); } #if DEBUG long memorySizeAfter = GC.GetTotalMemory(false); #endif } catch { } }