protected override void OnStartup(StartupEventArgs e) { List <Arg> args = ProcessArgs(e.Args); StartMinimized = args.Any(a => a.Type == ArgType.Minimized); _silent = args.Any(a => a.Type == ArgType.Silent); var arg = args.FirstOrDefault(a => a.Type == ArgType.Send); if (arg != null) { AttachConsole(-1); PrintHeader(); string[] cmds = arg.Param.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); var sys = SbmqSystem.Create(); try { foreach (var cmd in cmds) { var itm = sys.SavedCommands.Items.FirstOrDefault(c => c.DisplayName == cmd); if (itm != null) { Out(string.Format("Sending Command '{0}'...", cmd)); sys.SendCommand(itm.SentCommand.ConnectionStrings, itm.SentCommand.Queue, itm.SentCommand.Command); } else { Out(string.Format("No Command with name '{0}' found, exiting...", cmd)); } } } finally { sys.Manager.Terminate(); } Application.Current.Shutdown(0); return; } if (args.Where(a => (int)a.Type < 20).Count() > 0) { AttachConsole(-1); PrintHeader(); PrintHelp(); Application.Current.Shutdown(0); return; } if (!args.Any(a => a.Type == ArgType.Force)) { // Check if we are already running... Process currProc = Process.GetCurrentProcess(); Process existProc = Process.GetProcessesByName(currProc.ProcessName).Where(p => p.Id != currProc.Id).FirstOrDefault(); if (existProc != null) { try { // Show the already started SBMQM WindowTools.EnumWindows(new WindowTools.EnumWindowsProc((hwnd, lparam) => { uint procId; WindowTools.GetWindowThreadProcessId(hwnd, out procId); if (procId == existProc.Id) { if (WindowTools.SendMessage(hwnd, ServiceBusMQManager.MainWindow.WM_SHOWWINDOW, 0, 0) == 1) { return(false); } } return(true); }), 0); } finally { Application.Current.Shutdown(); } return; } } base.OnStartup(e); }