private void writeToFile(EasyThread sender, object parameters) { //operações com arquivos devem ser, preferencialmente, realizadas em threads sender.sleep(10); int cont = 0; var directory = this.appPath + "\\vars"; if (!System.IO.Directory.Exists(directory)) { System.IO.Directory.CreateDirectory(directory); } while (cont < this.cache.Count) { try { if (!this.cache.ElementAt(cont).Value.writed) { int tries = 5; int currentRetryInterval = 50; while (tries > 0) { try { string name = this.StringToFileName(this.cache.ElementAt(cont).Key); System.IO.File.WriteAllText(directory + "\\" + name, this.cache.ElementAt(cont).Value.value); this.cache[name].writed = true; tries = 0; } catch { Thread.Sleep(currentRetryInterval); currentRetryInterval += 50; } tries--; } } } catch { } cont++; } }
private void writeToFile(EasyThread sender, object parameters) { //operações com arquivos devem ser, preferencialmente, realizadas em threads sender.sleep(10); int cont = 0; while (cont < this.cache.Count) { try { if (!this.cache.ElementAt(cont).Value.writed) { int tries = 5; int currentRetryInterval = 50; while (tries > 0) { try { string name = getValidVarName(this.cache.ElementAt(cont).Key); write(directory + name, this.cache.ElementAt(cont).Value.value); this.cache[name].writed = true; tries = 0; } catch { Thread.Sleep(currentRetryInterval); currentRetryInterval += 50; } tries--; } } } catch { } cont++; } }