private void SaveResumeDataAlert(Core.save_resume_data_alert a) { Interlocked.MemoryBarrier(); TorrentHandle h = null; BinaryWriter bw = null; FileStream fs = null; try { h = a.handle; using (TorrentInfo ti = h.torrent_file()) using (Sha1Hash hash = h.info_hash()) { log.Debug("processing {0}", ti.name()); string newfilePath = ("./Fastresume/" + hash.ToString() + ".fastresume"); var data = Core.Util.bencode(a.resume_data); fs = new FileStream(newfilePath, FileMode.OpenOrCreate); bw = new BinaryWriter(fs); bw.Write(data); bw.Close(); log.Debug("done {0}", ti.name()); } //log.Debug(" for {0}", h.torrent_file().name()); //string newfilePath = ("./Fastresume/" + h.info_hash().ToString() + ".fastresume"); //var data = Core.Util.bencode(a.resume_data); //fs = new FileStream(newfilePath, FileMode.OpenOrCreate); //bw = new BinaryWriter(fs); //bw.Write(data); //bw.Close(); } finally { if (!ReferenceEquals(null, h)) { h.Dispose(); } if (!ReferenceEquals(null, bw)) { bw.Dispose(); } if (!ReferenceEquals(null, fs)) { fs.Dispose(); } } Interlocked.Decrement(ref outstanding_resume_data); if (outstanding_resume_data == 0 && no_more_resume) { no_more_data.Set(); } }