private void timer_Elapsed(object sender, ElapsedEventArgs e) { if (writeCount < maxCount) { try { File.AppendAllText(file, $"Log entry {DateTime.Now:u}\r\n"); StatusHandler?.UpdateStatus((short)(++writeCount * 100 / maxCount), $"Log file started at {lastWriteTime}"); } catch { } } if (writeCount >= maxCount) { timer.Enabled = false; writeCount = 0; StatusHandler?.TaskCompleted(0); } }
void timer_Elapsed(object sender, ElapsedEventArgs e) { if (writeCount < maxCount) { try { using (StreamWriter wri = File.AppendText(file)) wri.WriteLine("Log entry {0}", DateTime.Now); StatusHandler.UpdateStatus((short)(++writeCount * 100 / maxCount), $"Log file started at {lastWriteTime}"); } catch { } } if (writeCount >= maxCount) { timer.Enabled = false; writeCount = 0; StatusHandler.TaskCompleted(0); } }