From cc28b68dfef4e3f96ce00ad4fecd2f9f0a7b6400 Mon Sep 17 00:00:00 2001 From: MrShoenel Date: Thu, 8 Aug 2013 23:37:43 +0200 Subject: [PATCH] Added "ping now" functionality; some refactoring --- Program.cs | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/Program.cs b/Program.cs index 9cb0bf4..feefaf6 100644 --- a/Program.cs +++ b/Program.cs @@ -60,29 +60,43 @@ protected Timer InitializeTimer(TimeSpan interval) var timer = new Timer(interval.TotalMilliseconds); timer.Elapsed += (s, e) => { - if (settings.DriveSettings.Any(ds => ds.Ping)) - { - this.SwitchToWorkingIcon(); - } - - foreach (var d in settings.DriveSettings.Where(ds => ds.Ping)) - { - var guid = Guid.NewGuid().ToString(); - try - { - File.WriteAllText(d.DriveInfo.Name + guid, guid); - File.Delete(d.DriveInfo.Name + guid); - } - catch { } - } + this.PingDrives(); }; timer.Start(); return timer; } + private void PingDrives() + { + if (settings.DriveSettings.Any(ds => ds.Ping)) + { + this.SwitchToWorkingIcon(); + } + + foreach (var ds in settings.DriveSettings) + { + var guid = Guid.NewGuid().ToString(); + try + { + File.WriteAllText(ds.DriveInfo.Name + guid, guid); + File.Delete(ds.DriveInfo.Name + guid); + } + catch { } + } + } + protected void CreateTrayOptions() { + var pingNowItem = new MenuItem("Ping now"); + pingNowItem.Click += (s, e) => + { + this.PingDrives(); + }; + + trayMenu.MenuItems.Add(pingNowItem); + trayMenu.MenuItems.Add("-"); + var drivesMenu = new MenuItem("Ping Drives"); var drives = DriveInfo.GetDrives();