public static void Writer(string msg, string path, string file) { Debug.GC(true); Debug.Print("mem: " + Debug.GC(true)); lock (CardLock) { //SDC_flushSlow(); int bufferSize = msg.Length; Debug.Print("Attempting to write with buffer of " + bufferSize.ToString()); try { if (Detect.SD_Card() & File.Exists(path + file)) { using (var writestream = new FileStream(path + file, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite, bufferSize)) { StreamWriter SW = new StreamWriter(writestream); SW.Write(msg); SW.Flush(); SW.Close(); } } else if (Detect.SD_Card()) { if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } using (var writestream = new FileStream(path + file, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite, bufferSize)) { StreamWriter SW = new StreamWriter(writestream); SW.Write(msg); SW.Flush(); SW.Close(); } } } catch (Exception e) { Debug.Print("SD_Writer Failed " + e.Message); } DebugLED.Show(15, 500); } }
SDC_Flushed and remounted mem: 24732 Attempting to write with buffer of 1074 Failed allocation for 343 blocks, 4116 bytes Failed allocation for 343 blocks, 4116 bytes A first chance exception of type 'System.OutOfMemoryException' occurred in System.IO.dll SD_Writer FailedException was thrown: System.OutOfMemoryException
Debug.Print("mem: " + Debug.GC(true));