public App() { SingleInstanceManager.SingleInstanceCheck(); // Splash Screen should be created manually and after single-instance is checked //ShowSplashScreen(); }
/// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose(bool disposing) { if (disposing) { if (this.singleInstanceManager != null) { SingleInstanceManager sim2 = this.singleInstanceManager; SingleInstanceManager = null; sim2.Dispose(); sim2 = null; } if (this.floaterOpacityTimer != null) { this.floaterOpacityTimer.Tick -= new System.EventHandler(this.FloaterOpacityTimer_Tick); this.floaterOpacityTimer.Dispose(); this.floaterOpacityTimer = null; } if (this.components != null) { this.components.Dispose(); this.components = null; } } base.Dispose(disposing); }
public ShellWindow(SingleInstanceManager singleInstanceManager, ShellViewModel shellViewModel, IAppEvents appEvents, IAppSettingsService appSettingsService) { DataContext = shellViewModel; InitializeComponent(); singleInstanceManager.OnNewInstance += SingleInstanceManager_OnNewInstance; appEvents.OnDragDropModeChanged += AppEvents_OnDragDropModeChanged; dragDropHelper = new DragDropHelper(tabControl, new List <DragDropPair> { new DragDropPair(typeof(ListViewItem)), new DragDropPair(typeof(ListViewItem), typeof(TabItem)), new DragDropPair(typeof(ListViewItem), typeof(ListView)), new DragDropPair(typeof(TabItem)), new DragDropPair(typeof(TabItem), typeof(TabPanel)) }); fileDragDropHelper = new FileDragDropHelper(tabControl, new List <Type> { typeof(ListViewItem), typeof(TabItem) }, new List <Type> { typeof(TabControl) }); AppEvents_OnDragDropModeChanged(appSettingsService.DragDropMode); KeyDownHandlerEnabled = true; }
public static void Main() { // Setup derived settings class Settings.Initialise(); String appName = "OptikeyPro"; Action runApp = () => { splashScreen = new SplashScreen("/Resources/Icons/OptikeyProSplash.png"); splashScreen.Show(false); var application = new App(); application.InitializeComponent(); application.Run(); }; if (Settings.Default.AllowMultipleInstances) { runApp(); } else { using (_manager = SingleInstanceManager.Initialize( new SingleInstanceManagerSetup(appName))) { runApp(); } } }
public void RunApplicationTest() { var parameters = new[] { "a", "b", "longParam with spaces and ` \x305 other chars" }; var manager = SingleInstanceManager.CreateManager("unitTest"); var start1 = manager.RunApplication(new string[] { }); Assert.AreEqual(true, start1); var m = new Barrier(2); manager.SecondInstanceStarted += (sender, e) => { CollectionAssert.AreEqual(parameters, e.CommandLineParameters); m.SignalAndWait(); m.Dispose(); }; var t = new Thread(() => { var start2 = manager.RunApplication(parameters); Assert.AreEqual(false, start2); }); t.Start(); t.Join(); if (!m.SignalAndWait(10000)) { Assert.Warn("Signal timed out"); } ; manager.Shutdown(); }
public static void Main(string[] args) { //Create our new single-instance manager SingleInstanceManager manager = new SingleInstanceManager(); manager.Run(args); }
public void SimpleRunApplicationTest() { var manager = SingleInstanceManager.CreateManager("unitTest"); var start1 = manager.RunApplication(new string[] { }); Assert.AreEqual(true, start1); var secondSignaled = false; manager.SecondInstanceStarted += (sender, e) => { secondSignaled = true; }; var t = new Thread(() => { var start2 = manager.RunApplication(new string[] { }); Assert.AreEqual(false, start2); }); t.Start(); t.Join(); Assert.That(secondSignaled); manager.Shutdown(); }
static void Main() { SingleInstanceManager manager = new SingleInstanceManager(); //manager.Run(new[] { "test" }); manager.Run(Environment.GetCommandLineArgs()); }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); //Application.Run(new MainForm()); SingleInstanceManager manager = new SingleInstanceManager();//单实例管理器 manager.Run(new string[] { }); }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); //Application.Run(new MainForm()); SingleInstanceManager manager = new SingleInstanceManager();//单实例管理器 manager.Run(new string[] { }); }
public static void Main(string[] args) { #if DEBUG RunApp(new ReadOnlyCollection <string>(args)); #else SingleInstanceManager singleInstanceApp = new SingleInstanceManager(); singleInstanceApp.Run(args); #endif }
static void Main() { using (SingleInstanceManager manager = SingleInstanceManager.Initialize(GetSingleInstanceManagerSetup())) { App app = new App(); app.InitializeComponent(); app.Run(); } }
static void Main() { var applicationId = new Guid("b54f7b0d-87f9-4df9-9686-4d8fd76066dc"); if (SingleInstanceManager.VerifySingleInstance(applicationId)) { SingleInstanceManager.OtherInstanceStarted += OnOtherInstanceStarted; // start the application } }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); MainForm mainForm = new MainForm(); using (SingleInstanceManager manager = SingleInstanceManager.Initialize(GetSingleInstanceManagerSetup(mainForm))) { Application.Run(mainForm); } }
protected override void OnStartup(StartupEventArgs e) { if (!SingleInstanceManager.Check()) { Shutdown(); } else { #warning Message事件处理程序 } }
public App() { this.mutex = SingleInstanceManager.TryAcquireMutex(); this.namedPipeManager = new NamedPipeManager(Assembly.GetExecutingAssembly().FullName); var autoSuspendHelper = new AutoSuspendHelper(this); GC.KeepAlive(autoSuspendHelper); BlobCache.ApplicationName = Assembly.GetExecutingAssembly().GetName().Name; }
public static void Main() { using (_manager = SingleInstanceManager.Initialize(GetSingleInstanceManagerSetup())) { splashScreen = new SplashScreen("/Resources/Icons/OptikeySymbolSplash.png"); splashScreen.Show(false); var application = new App(); application.InitializeComponent(); application.Run(); } }
public App() { this.mutex = SingleInstanceManager.TryAcquireMutex(); this.namedPipeManager = new NamedPipeManager(Assembly.GetExecutingAssembly()?.FullName ?? String.Empty); PlatformRegistrationManager.SetRegistrationNamespaces(RegistrationNamespace.Wpf); var autoSuspendHelper = new AutoSuspendHelper(this); GC.KeepAlive(autoSuspendHelper); BlobCache.ApplicationName = Assembly.GetExecutingAssembly().GetName()?.Name ?? String.Empty; }
static void Main() { try { using (SingleInstanceManager manager = SingleInstanceManager.Initialize(GetSingleInstanceManagerSetup())) { App app = new App(); app.InitializeComponent(); app.Run(); } } catch (ApplicationInstanceAlreadyExistsException) { } }
private static void Main(string[] args) { const string appKey = "a78dd11e-aec3-4c68-aa5a-4410c51d45fd"; using (var singleInstance = new SingleInstanceManager(appKey, TimeSpan.Zero)) { singleInstance.OnNewInstance += SingleInstance_OnNewInstance; if (singleInstance.FirstInstance) { StartApp(); } else { singleInstance.SendNofitication(); AppStopped(); } } }
protected override void OnClosing(CancelEventArgs e) { if (!e.Cancel) { if (this.appWorkspace != null) { CloseAllWorkspacesAction cawa = new CloseAllWorkspacesAction(); this.appWorkspace.PerformAction(cawa); e.Cancel = cawa.Cancelled; } } if (!e.Cancel) { SaveSettings(); if (this.floaters != null) { foreach (Form hideMe in this.floaters) { hideMe.Hide(); } } this.Hide(); if (this.queuedInstanceMessages != null) { this.queuedInstanceMessages.Clear(); } SingleInstanceManager sim2 = this.singleInstanceManager; SingleInstanceManager = null; if (sim2 != null) { sim2.Dispose(); sim2 = null; } } base.OnClosing(e); }
static void Main() { try { //处理未捕获的异常 Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); //处理UI线程异常 Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException); //处理非UI线程异常 AppDomain.CurrentDomain.UnhandledException += new System.UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); SingleInstanceManager manager = new SingleInstanceManager();//单实例管理器 manager.Run(new string[] { }); } catch (Exception ex) { string str = ""; string strDateInfo = "出现应用程序未处理的异常:" + DateTime.Now.ToString() + "\r\n"; if (ex != null) { str = string.Format(strDateInfo + "异常类型:{0}\r\n异常消息:{1}\r\n异常信息:{2}\r\n", ex.GetType().Name, ex.Message, ex.StackTrace); } else { str = string.Format("应用程序线程错误:{0}", ex); } writeLog(str); ErrorCollection EC = new ErrorCollection(1); EC.ShowDialog(); //MessageBox.Show("发生致命错误,程序即将关闭,请及时联系作者!", "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error); Process.GetCurrentProcess().Kill(); } //Application.Run(new frmMain()); //屏蔽掉了以前的加载头 }
static void Main() { try { //处理未捕获的异常 Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); //处理UI线程异常 Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException); //处理非UI线程异常 AppDomain.CurrentDomain.UnhandledException += new System.UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); SingleInstanceManager manager = new SingleInstanceManager();//单实例管理器 manager.Run(new string[] { }); } catch (Exception ex) { string str = ""; string strDateInfo = "出现应用程序未处理的异常:" + DateTime.Now.ToString() + "\r\n"; if (ex != null) { str = string.Format(strDateInfo + "异常类型:{0}\r\n异常消息:{1}\r\n异常信息:{2}\r\n", ex.GetType().Name, ex.Message, ex.StackTrace); } else { str = string.Format("应用程序线程错误:{0}", ex); } writeLog(str); ErrorCollection EC = new ErrorCollection(1); EC.ShowDialog(); //MessageBox.Show("发生致命错误,程序即将关闭,请及时联系作者!", "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error); Process.GetCurrentProcess().Kill(); } //Application.Run(new frmMain()); //屏蔽掉了以前的加载头 }
public MainWindow() { Instance = this; InitializeComponent(); _helper = ServiceProvider.Get <MainWindowHelper>(); _helper.MainViewModel.Init(!App.CmdOptions.NoPersist, !App.CmdOptions.Reset); _helper.HotkeySetup.Setup(); _helper.TimerModel.Init(); Loaded += (Sender, Args) => { RepositionWindowIfOutside(); ServiceProvider.Get <WebcamPage>().SetupPreview(); _helper.HotkeySetup.ShowUnregistered(); }; if (App.CmdOptions.Tray || _helper.Settings.Tray.MinToTrayOnStartup) { Hide(); } Closing += (Sender, Args) => { if (!TryExit()) { Args.Cancel = true; } }; // Register to bring this instance to foreground when other instances are launched. SingleInstanceManager.StartListening(WakeApp); }
protected override void OnStartup(StartupEventArgs e) { try { singleInstanceManager = new SingleInstanceManager(appKey, TimeSpan.Zero); if (!AppConfig.MultiInst && !singleInstanceManager.FirstInstance) { MessageBox.Show("App is currently running", "Barcodes", MessageBoxButton.OK, MessageBoxImage.Stop); singleInstanceManager.SendNofitication(); Shutdown(); } else { TrySetCulture(); base.OnStartup(e); } } catch (Exception exc) { MessageBox.Show($"Exception on startup occured: {exc.Message}", "Barcodes", MessageBoxButton.OK, MessageBoxImage.Error); } }
/// <summary> /// Runs this application by launching the specified form. /// </summary> /// <param name="form">The application's main form.</param> public void Run(System.Windows.Forms.Form form) { if (form == null) { throw new ArgumentNullException("form"); } if (applicationType != ThisApplicationType.WindowsFormsApplication) { throw new ApplicationException(string.Format("Bad application type: {0}; should be {1}", applicationType, ThisApplicationType.WindowsFormsApplication)); } if (IsSingleInstance) { SingleInstanceManager.Run(form); } else { System.Windows.Forms.Application.Run(form); } }
/// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose(bool disposing) { if (disposing) { if (this.singleInstanceManager != null) { SingleInstanceManager sim2 = this.singleInstanceManager; SingleInstanceManager = null; sim2.Dispose(); sim2 = null; } if (this.floaterOpacityTimer != null) { this.floaterOpacityTimer.Tick -= new System.EventHandler(this.FloaterOpacityTimer_Tick); this.floaterOpacityTimer.Dispose(); this.floaterOpacityTimer = null; } if (this.components != null) { this.components.Dispose(); this.components = null; } } try { base.Dispose(disposing); } catch (RankException) { // System.Windows.Forms.PropertyStore // Discard error - bug #2746 } }
static void Main() { if (Environment.OSVersion.Version.Major >= 6) { // prevent overlay from capturing only a portion of the desktop ApiScreenCapture.SetProcessDPIAware(); } using (var app = new SingleInstanceManager()) { const int singleInstanceWaitMs = 1000; if (!app.IsFirstInstance(singleInstanceWaitMs)) { // force single instance MessageBox.Show(@"An instance of PinWin is already running."); return; } // else we are good to run the app Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm()); } }
public static void Main(string[] args) { SingleInstanceManager manager = new SingleInstanceManager(); manager.Run(args); }
protected override async void OnStartup(StartupEventArgs e) { base.DispatcherUnhandledException += App_DispatcherUnhandledException; AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException; await Host.StartAsync(); SingleInstanceManager singleInstanceManager = Host.Services.GetRequiredService <SingleInstanceManager>(); _logger.Value.LogInformation("Starting App."); if (!singleInstanceManager.IsFirstInstance) { _logger.Value.LogInformation("I am not the first instance. Shutting down ..."); base.Shutdown(0); return; } base.ShutdownMode = ShutdownMode.OnExplicitShutdown; singleInstanceManager.SecondInstanceStarted += OnSecondInstanceStarted; bool createUi = true; foreach (string arg in e.Args) { switch (arg) { case "-tray": createUi = false; _logger.Value.LogInformation("Launch argument '{0}' found, don't create a UI.", arg); break; default: _logger.Value.LogWarning("Got invalid launch argument '{0}', ignoring.", arg); break; } } _logger.Value.LogTrace("Setting up tray icon."); TrayIconManager trayIconManager = Host.Services.GetRequiredService <TrayIconManager>(); trayIconManager.IconVisible = true; trayIconManager.ItemExitClick += (sender, eventArgs) => _ = App.GracefulShutdownAsync(); trayIconManager.DoubleClick += (sender, eventArgs) => this.ShowCreateMainWindow(); ProfileRepository profileRepository = Host.Services.GetRequiredService <ProfileRepository>(); await profileRepository.LoadProfilesAsync(); if (createUi) { _logger.Value.LogInformation("Creating MainWindow on startup."); this.ShowCreateMainWindow(); } SimConnectManager scm = Host.Services.GetRequiredService <SimConnectManager>(); await scm.StartAsync(); _ = Host.Services.GetRequiredService <DeviceBindingManager>(); }
public static void Main(string[] args) { SingleInstanceManager manager = new SingleInstanceManager(); manager.Run(args); }
public static void Main(string[] args) { SingleInstanceManager SingleInsctancMgr = new SingleInstanceManager(); SingleInsctancMgr.Run(args); }
public static void Main(string[] args) { SingleInstanceManager.Launcher <App>(args); }
private void StartPart2() { // Set up locale / resource details string locale = Settings.CurrentUser.GetString(SettingNames.LanguageName, null); if (locale == null) { locale = Settings.SystemWide.GetString(SettingNames.LanguageName, null); } if (locale != null) { try { CultureInfo ci = new CultureInfo(locale, true); Thread.CurrentThread.CurrentUICulture = ci; } catch (Exception) { // Don't want bad culture name to crash us } } // Check system requirements if (!OS.CheckOSRequirement()) { string message = PdnResources.GetString("Error.OSRequirement"); Utility.ErrorBox(null, message); return; } // Parse command-line arguments if (this.args.Length == 1 && this.args[0] == Updates.UpdatesOptionsDialog.CommandLineParameter) { Updates.UpdatesOptionsDialog.ShowUpdateOptionsDialog(null, false); } else { SingleInstanceManager singleInstanceManager = new SingleInstanceManager(InvariantStrings.SingleInstanceMonikerName); // If this is not the first instance of PDN.exe, then forward the command-line // parameters over to the first instance. if (!singleInstanceManager.IsFirstInstance) { singleInstanceManager.FocusFirstInstance(); foreach (string arg in this.args) { singleInstanceManager.SendInstanceMessage(arg, 30); } singleInstanceManager.Dispose(); singleInstanceManager = null; return; } // Create main window this.mainForm = new MainForm(this.args); this.mainForm.SingleInstanceManager = singleInstanceManager; singleInstanceManager = null; // mainForm owns it now // 3 2 1 go Application.Run(this.mainForm); try { this.mainForm.Dispose(); } catch (Exception) { } this.mainForm = null; } }