Example #1
0
        /// <summary>
        /// Called in order to execute the boot process.
        /// </summary>
        /// <param name="serviceProvider">The service provider.</param>
        protected virtual void OnBoot(IServiceProvider serviceProvider)
        {
#if !SILVERLIGHT
            var broker = serviceProvider.GetService <IMessageBroker>();
            broker.Subscribe <ApplicationShutdownRequest>(this, InvocationModel.Safe, (s, m) =>
            {
                this.OnShutdownCore(ApplicationShutdownReason.UserRequest);
            });

            var args = new SingletonApplicationStartupArgs(this.singleton);
            this.HandleSingletonApplicationStartup(args);

            if (args.AllowStartup)
            {
                if (this.bootHandler != null)
                {
                    this.bootHandler(serviceProvider);
                }
            }
            else
            {
                this.OnShutdownCore(ApplicationShutdownReason.MultipleInstanceNotAllowed);
            }
#else
            if (this.bootHandler != null)
            {
                this.bootHandler(serviceProvider);
            }
#endif
        }
Example #2
0
        /// <summary>
        /// Handles the singleton application scope.
        /// </summary>
        /// <param name="args">The args.</param>
        protected virtual void HandleSingletonApplicationStartup(SingletonApplicationStartupArgs args)
        {
            if (args.Scope != SingletonApplicationScope.NotSupported)
            {
                String mutexName = this.key;
                switch (args.Scope)
                {
                case SingletonApplicationScope.Local:
                    mutexName = @"Local\" + mutexName;
                    break;

                case SingletonApplicationScope.Global:
                    mutexName = @"Global\" + mutexName;
                    break;
                }

                this.mutex        = new Mutex(false, mutexName);
                args.AllowStartup = this.mutex.WaitOne(TimeSpan.Zero, false);

                if (this.onSingletonApplicationStartup != null)
                {
                    this.onSingletonApplicationStartup(args);
                }
            }
        }