using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ClassLibrary { public class TraceTotalMemory { static string _outDirName; TraceTotalMemory() { } static private void WriteTraceFile(StreamWriter sw, string sLine) { try { sw.WriteLine(sLine); } catch (Exception e) { } finally { } } static public void ClearTraceFile(string outDirName) { _outDirName = outDirName; StreamWriter sw = new StreamWriter(outDirName + "\\trace.txt"); WriteTraceFile(sw, ""); sw.Close(); } static public void WriteTotalMemory(string outDirName, string notice) { _outDirName = outDirName; StreamWriter sw = new StreamWriter(outDirName + "\\trace.txt", true); WriteTraceFile(sw, notice); long totalMemory = 0; try { #if DEBUG GC.Collect(); #endif totalMemory = GC.GetTotalMemory(false); WriteTraceFile(sw, totalMemory.ToString()); } catch (Exception xx) { Console.WriteLine(xx.ToString()); Console.ReadLine(); } sw.Close(); sw.Dispose(); } static public void WriteTotalMemory(string notice) { StreamWriter sw = new StreamWriter(_outDirName + "\\trace.txt", true); WriteTraceFile(sw, notice); long totalMemory = 0; try { #if DEBUG GC.Collect(); #endif totalMemory = GC.GetTotalMemory(false); WriteTraceFile(sw, totalMemory.ToString()); } catch (Exception xx) { Console.WriteLine(xx.ToString()); Console.ReadLine(); } sw.Close(); sw.Dispose(); } } }