private static void Start(string[] args) { Logger.Title = "DNSAgent - Starting ..."; System.Version version = Assembly.GetExecutingAssembly().GetName().Version; DateTime buildTime = Utils.RetrieveLinkerTimestamp(Assembly.GetExecutingAssembly().Location); string programName = "DNSAgent " + version.Major + "." + version.Minor + "." + version.Build + ""; Logger.Info("{0} (build at {1})\n", programName, buildTime.ToString(CultureInfo.CurrentCulture)); Logger.Info("Starting..."); Options options = ReadOptions(); Rules rules = ReadRules(); string[] listenEndpoints = options.ListenOn.Split(','); var startedEvent = new MrTe.Threading.Tasks.CountdownEvent(listenEndpoints.Length); lock (DnsAgents) { foreach (string listenOn in listenEndpoints) { var agent = new DnsAgent(options, rules, listenOn.Trim(), AgentCommonCache); agent.Started += () => startedEvent.Signal(); DnsAgents.Add(agent); } } lock (DnsAgents) { foreach (var agent in DnsAgents) { agent.Start(); } } startedEvent.Wait(); Logger.Title = "DNSAgent - Listening ..."; Logger.Info("DNSAgent has been started."); Logger.Info("Press Ctrl-L to clear screen, Ctrl-R to reload configurations, Ctrl-C to stop and quit."); _ConsoleTask = new Thread(new ThreadStart(ConsoleTask_Run)); _ConsoleTask.Start(); }
private static void Start(string[] args) { Logger.Title = "DNSAgent - Starting ..."; System.Version version = Assembly.GetExecutingAssembly().GetName().Version; DateTime buildTime = Utils.RetrieveLinkerTimestamp(Assembly.GetExecutingAssembly().Location); string programName = "DNSAgent " + version.Major + "." + version.Minor + "." + version.Build + ""; Logger.Info("{0} (build at {1})\n", programName, buildTime.ToString(CultureInfo.CurrentCulture)); Logger.Info("Starting..."); Options options = ReadOptions(); Rules rules = ReadRules(); string[] listenEndpoints = options.ListenOn.Split(','); var startedEvent = new CountdownEvent(listenEndpoints.Length); lock (DnsAgents) { foreach (string listenOn in listenEndpoints) { var agent = new DnsAgent(options, rules, listenOn.Trim(), AgentCommonCache); agent.Started += () => startedEvent.Signal(); DnsAgents.Add(agent); } } if (Environment.UserInteractive) { lock (DnsAgents) { if (DnsAgents.Any(agent => !agent.Start())) { PressAnyKeyToContinue(); return; } } startedEvent.Wait(); Logger.Title = "DNSAgent - Listening ..."; Logger.Info("DNSAgent has been started."); Logger.Info("Press Ctrl-L to clear screen, Ctrl-R to reload configurations, Ctrl-C to stop and quit."); /* * Task.Run(() => * { * * }); */ _ConsoleTask = new Thread(new ThreadStart(ConsoleTask_Run)); _ConsoleTask.Start(); MenuItem hideMenuItem = new MenuItem(options.HideOnStart ? "Show" : "Hide"); if (options.HideOnStart) { ShowWindow(GetConsoleWindow(), SwHide); } hideMenuItem.Click += (sender, eventArgs) => { if (hideMenuItem.Text == "Hide") { ShowWindow(GetConsoleWindow(), SwHide); hideMenuItem.Text = "Show"; } else { ShowWindow(GetConsoleWindow(), SwShow); hideMenuItem.Text = "Hide"; } }; _contextMenu = new ContextMenu(new[] { new MenuItem("Clear", (sender, eventArgs) => Clear()), hideMenuItem, new MenuItem("Reload", (sender, eventArgs) => Reload()), new MenuItem("Exit", (sender, eventArgs) => Stop(false)) }); _notifyIcon = new NotifyIcon { Icon = Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location), ContextMenu = _contextMenu, Text = programName, Visible = true }; _notifyIcon.MouseClick += (sender, eventArgs) => { if (eventArgs.Button == MouseButtons.Left) { hideMenuItem.PerformClick(); } }; Application.Run(); } else { lock (DnsAgents) { foreach (var agent in DnsAgents) { agent.Start(); } } Logger.Info("DNSAgent has been started."); } }