/// <summary> /// Constructs and initializes a new instance of the single instance manager. /// </summary> /// <param name="setup">Setup information for the single instance manager.</param> /// <returns>An initialized single instance manager.</returns> /// <remarks> /// Use this method to initialize a single instance manager with the given setup information. /// Note that normally only one call to this method should be performed, at the beggining of the application execution. /// </remarks> public static SingleInstanceManager Initialize(SingleInstanceManagerSetup setup) { if (setup == null) throw new ArgumentNullException("setup"); // Initialize the SingleInstanceManager instance DeliveryStrategyFactory factory = setup.Factory ?? GetDefaultFactory(); SingleInstanceManager instance = new SingleInstanceManager (GenerateUserLocalId(setup.ApplicationId), setup.ArgumentsHandler, factory.CreateStrategy(), setup.ArgumentsProvider, setup.ArgumentsHandlerInvoker, setup.InstanceNotificationOption, setup.DelivaryFailureNotification); if (!instance.TryEnsureFirstInstance()) { // If this is not the first application instance (another instance is already running) then we need to exit/throw instance.Dispose(); instance = null; switch (setup.TerminationOption) { case TerminationOption.Exit: Environment.Exit(setup.ExitCode); break; case TerminationOption.Throw: throw new ApplicationInstanceAlreadyExistsException(); default: Debug.Assert(false, "Should never be here!"); throw new Exception("Should never be here!"); } } return instance; }
/// <summary> /// Constructs and initializes a new instance of the single instance manager. /// </summary> /// <param name="setup">Setup information for the single instance manager.</param> /// <returns>An initialized single instance manager.</returns> /// <remarks> /// Use this method to initialize a single instance manager with the given setup information. /// Note that normally only one call to this method should be performed, at the beggining of the application execution. /// </remarks> public static SingleInstanceManager Initialize(SingleInstanceManagerSetup setup) { if (setup == null) { throw new ArgumentNullException("setup"); } // Initialize the SingleInstanceManager instance DeliveryStrategyFactory factory = setup.Factory ?? GetDefaultFactory(); SingleInstanceManager instance = new SingleInstanceManager (GenerateUserLocalId(setup.ApplicationId), setup.ArgumentsHandler, factory.CreateStrategy(), setup.ArgumentsProvider, setup.ArgumentsHandlerInvoker, setup.InstanceNotificationOption, setup.DelivaryFailureNotification); if (!instance.TryEnsureFirstInstance()) { // If this is not the first application instance (another instance is already running) then we need to exit/throw instance.Dispose(); instance = null; switch (setup.TerminationOption) { case TerminationOption.Exit: Environment.Exit(setup.ExitCode); break; case TerminationOption.Throw: throw new ApplicationInstanceAlreadyExistsException(); default: Debug.Assert(false, "Should never be here!"); throw new Exception("Should never be here!"); } } return(instance); }