public static Map Read(string file) { if (!File.Exists(file)) { Write(file, new Map()); return new Map(); } else { FileInfo inf = new FileInfo(file); while (inf.IsFileLocked()) { Console.WriteLine("Wait..."); }; try { using (Stream s = File.Open(file, FileMode.Open)) { System.Xml.Serialization.XmlSerializer reader = new System.Xml.Serialization.XmlSerializer(typeof(Map)); return (Map)reader.Deserialize(s); } } catch (Exception ex) { Console.WriteLine(ex.GetBaseException().ToString()); return new Map(); } } }
public static bool Wait(this FileInfo fileInfo, TimeSpan wait) { var period = TimeSpan.FromSeconds(2); if (period > wait) { period = wait; } while (fileInfo.IsFileLocked() && wait.TotalMilliseconds >= 0) { Thread.Sleep(period); wait -= period; } return(fileInfo.IsFileLocked()); }
public static void Wait(this FileInfo fileInfo) { var period = TimeSpan.FromSeconds(2); while (fileInfo.IsFileLocked()) { Thread.Sleep(period); } }
private void checkFileFunctionThread(object obj) { while (true) { if (setting.DateFile > 0) { List<string> fileRecord = Directory.GetFiles(setting.Folder, "*.mp4", SearchOption.AllDirectories).ToList(); if (fileRecord != null && fileRecord.Count > 0) { foreach (string file in fileRecord) { FileInfo inf = new FileInfo(file); if (inf.Exists && inf.CreationTime.Date < DateTime.Now.Date) { double day = (DateTime.Now.Date - inf.CreationTime.Date).TotalDays; if (day > setting.DateFile && !inf.IsFileLocked()) { inf.Delete(); } } } } } Thread.Sleep(24 * 3600 * 1000); } }
void Cleanup() { var fi = new FileInfo(_testName + ".database"); if (fi.Exists) while (fi.IsFileLocked()) Thread.Sleep(100); fi.Delete(); }
protected override void Cleanup() { base.Cleanup(); var fi = new FileInfo(_testName + ".database.catIndex.location"); if (fi.Exists) while (fi.IsFileLocked()) Thread.Sleep(100); fi.Delete(); }
protected virtual void Cleanup() { var fi = new FileInfo(_testName + ".xml"); if (fi.Exists) while (fi.IsFileLocked()) Thread.Sleep(100); fi.Delete(); fi = new FileInfo(_testName + ".index"); if (fi.Exists) while (fi.IsFileLocked()) Thread.Sleep(100); fi.Delete(); fi = new FileInfo(_testName + ".test.index"); if (fi.Exists) while (fi.IsFileLocked()) Thread.Sleep(100); fi.Delete(); fi = new FileInfo(_testName + ".database"); if (fi.Exists) while (fi.IsFileLocked()) Thread.Sleep(100); fi.Delete(); fi = new FileInfo(_testName + ".database.index"); if (fi.Exists) while (fi.IsFileLocked()) Thread.Sleep(100); fi.Delete(); fi = new FileInfo(_testName + ".subscriber.database"); if (fi.Exists) while (fi.IsFileLocked()) Thread.Sleep(100); fi.Delete(); fi = new FileInfo(_testName + ".subscriber.database.index"); if (fi.Exists) while (fi.IsFileLocked()) Thread.Sleep(100); fi.Delete(); fi = new FileInfo(_testName + ".subscriber.database"); if (fi.Exists) while (fi.IsFileLocked()) Thread.Sleep(100); fi.Delete(); fi = new FileInfo(_testName + ".subscriber.database.index"); if (fi.Exists) while (fi.IsFileLocked()) Thread.Sleep(100); fi.Delete(); fi = new FileInfo(_testName + ".catalog.indexUpdate"); if (fi.Exists) while (fi.IsFileLocked()) Thread.Sleep(100); fi.Delete(); fi = new FileInfo(_testName + ".scenario"); if (fi.Exists) while (fi.IsFileLocked()) Thread.Sleep(100); fi.Delete(); fi = new FileInfo(_testName + ".database.catIndex.index"); if (fi.Exists) while (fi.IsFileLocked()) Thread.Sleep(100); fi.Delete(); fi = new FileInfo(_testName + ".database.cascade.index"); if (fi.Exists) while (fi.IsFileLocked()) Thread.Sleep(100); fi.Delete(); }