void DumpFileAsync() { try { string folder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); folder = folder + Path.DirectorySeparatorChar + "firebwall"; folder = folder + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar; folder = folder + Path.DirectorySeparatorChar + "SaveFlashVideo" + Path.DirectorySeparatorChar; if (!Directory.Exists(folder + "temp")) { Directory.CreateDirectory(folder + "temp"); } string extension = ".flv"; switch (Type) { case "video/vnd.avi": case "video/avi": case "video/masvideo": case "video/x-msvideo": extension = ".avi"; break; case "video/x-mp4": extension = ".mp4"; break; case "audio/mp4": extension = ".m4a"; break; case "audio/mpeg": case "audio/MPA": case "audio/mpa-robust": extension = ".mp3"; break; } tempFile = folder + "temp" + Path.DirectorySeparatorChar + DateTime.Now.Ticks.ToString() + "-" + ((uint)quad.GetHashCode()).ToString() + extension; FileStream bin = new FileStream(tempFile, FileMode.Append); DateTime last = DateTime.Now; while (!done) { Thread.Sleep(10); if ((DateTime.Now - last).TotalSeconds > 30) { break; } Queue <byte[]> dataQueue = swapQueue.DumpBuffer(); foreach (byte[] t in dataQueue) { last = DateTime.Now; bin.Write(t, 0, t.Length); written += (uint)t.Length; } } Queue <byte[]> q = swapQueue.DumpBuffer(); foreach (byte[] t in q) { last = DateTime.Now; bin.Write(t, 0, t.Length); written += (uint)t.Length; } q = swapQueue.DumpBuffer(); foreach (byte[] t in q) { last = DateTime.Now; bin.Write(t, 0, t.Length); written += (uint)t.Length; } bin.Close(); if (outputFile == null) { outputFile = folder + GetMD5HashFromFile(tempFile) + extension; } File.Move(tempFile, outputFile); } catch { } }