private void StartAsMainProcess(string[] args) { notifyIcon = new MainNotifyIcon(); notifyIcon.CloseAll += (s, e) => photoWindows.CloseAll(false); notifyIcon.Quit += (s, e) => Shutdown(); bool openedSomething = false; //open windows from last time using (var db = new WindowDbContext()) { foreach (var windowData in db.Windows) { OpenPhotoWindowOnNewThread(windowData); openedSomething = true; } } //open images from args if (args != null) { for (int i = 0; i < args.Length; i++) { //todo: validate path OpenPhotoWindowOnNewThread(new PhotoWindowData(args[i])); openedSomething = true; } } //if nothing else opened and the user started us if (!openedSomething) //todo: and started by user { OpenPhotoWindowOnNewThread(); } }