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 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); } }