private static async Task RunWatcherAsync() { using (var watch = new Watcher()) { var drvs = DriveInfo.GetDrives(); foreach (var drv in drvs) { if (drv.DriveType == DriveType.Fixed) { watch.Add(new Request(drv.Name, true)); } } // prepare the console watcher so we can output pretty messages. var _ = new ConsoleWatch(watch); // start watching watch.Start(); // listen for the Ctrl+C await Task.Delay(5000).ConfigureAwait(false); // stop everything. watch.Stop(); } }
private static void RunAndWait() { using (var watch = new Watcher()) { var drvs = DriveInfo.GetDrives(); foreach (var drv in drvs) { if (drv.DriveType == DriveType.Fixed) { watch.Add(new Request(drv.Name, true, new Rates(50))); } } // prepare the console watcher so we can output pretty messages. var _ = new ConsoleWatch(watch); // start watching watch.Start(); Console.WriteLine("Press Ctrl+C to stop to exit."); WaitForCtrlC(); // stop everything. watch.Stop(); } }
private static async Task RunAndRenameFolderInRoot() { using (var watch = new Watcher()) { var drvs = DriveInfo.GetDrives(); foreach (var drv in drvs) { if (drv.DriveType == DriveType.Fixed) { watch.Add(new Request(drv.Name, true)); } } //const string path = "z:\\"; //watch.Add(new Request(path, true, new Rates(50, 0))); watch.OnLoggerAsync += async(e, token) => { await Task.Yield(); Console.WriteLine($"[{DateTime.UtcNow:HH:mm:ss.ffff}]:{e.Message}"); }; // prepare the console watcher so we can output pretty messages. var _ = new ConsoleWatch(watch); // start watching watch.Start(); var cts = new CancellationTokenSource(); // start the renaming of folder const string path = "z:\\"; var task = RenameFolders($"{path}\\myoddweb.{Guid.NewGuid()}", 1000, cts.Token); Console.WriteLine("Press Ctrl+C to stop to exit."); WaitForCtrlC(); // stop everything. watch.Stop(); // only stop the task now // in case errors are thrown durring the shutdown itself cts.Cancel(); // wait for the task await Task.WhenAll(task).ConfigureAwait(false); } }
private static void Main() { try { Console.WriteLine("Press Ctrl+C to stop the monitors."); // start the monitor. var watch = new Watcher(); var drvs = System.IO.DriveInfo.GetDrives(); foreach (var drv in drvs) { if (drv.DriveType == System.IO.DriveType.Fixed) { watch.Add(new Request(drv.Name, true)); } } // prepare the console watcher so we can output pretty messages. var _ = new ConsoleWatch(watch); // start watching watch.Start(); // listen for the Ctrl+C WaitForCtrlC(); // stop everything. watch.Stop(); } catch (Exception ex) { Console.WriteLine(ex.Message); while (ex.InnerException != null) { ex = ex.InnerException; Console.WriteLine(ex.Message); } } }
private static void Main() { try { Console.WriteLine(Environment.Is64BitProcess ? "x64 version" : "x86 version"); Console.WriteLine("Press Ctrl+C to stop the monitors."); // start the monitor. using (var watch = new Watcher()) { var drvs = System.IO.DriveInfo.GetDrives(); foreach (var drv in drvs) { if (drv.DriveType == System.IO.DriveType.Fixed) { watch.Add(new Request(drv.Name, true)); } } // prepare the console watcher so we can output pretty messages. var _ = new ConsoleWatch(watch); // start watching watch.Start(); // listen for the Ctrl+C WaitForCtrlC(); // stop everything. watch.Stop(); } } catch (Exception ex) { WriteException(ex); } }