Example #1
0
        private Mutex mutex;                                    // single instance mutex


        //========================================================================================
        // Constructor
        //========================================================================================

        public App()
            : base()
        {
            // for development, explicitly override workstation UI culture
            OverrideUICulture();

            // given the /u parameter, we must uninstall the app
            CheckUninstall();

            // verify that iTunes is installed, otherwise there's no point, is there?
            EnsureiTunesInstalled();

            // allow only a single instance to run at a time
            try
            {
                mutex = Mutex.OpenExisting(Resx.I_SingletonID);

                // successfully opened existing mutex... another instance of iTuner is already
                // running, so check if iTunes is also running; if it is then assume we're a
                // duplicate and politely kill overselves.  otherwise, if iTunes is not running
                // assume that the other instance has gone rogue and needs to be assassinated!

                if (iTunesRunning())
                {
                    MessageBox.Show(
                        String.Format(CultureInfo.CurrentCulture,
                                      Resx.SingletonMessage, Resx.I_ApplicationTitle),
                        Resx.I_ApplicationTitle,
                        MessageBoxButton.OK, MessageBoxImage.Information);

                    Application.Current.Shutdown();
                    return;
                }
                else
                {
                    StopiTuner();
                    mutex = new Mutex(true, Resx.I_SingletonID);
                }
            }
            catch (WaitHandleCannotBeOpenedException)
            {
                mutex = new Mutex(true, Resx.I_SingletonID);
            }

            // passed the singleton test... wire up exception handling

            this.DispatcherUnhandledException +=
                new DispatcherUnhandledExceptionEventHandler(CatchUnhandledUIExceptions);

            AppDomain.CurrentDomain.UnhandledException +=
                new UnhandledExceptionEventHandler(CatchUnhandledBackgroundExceptions);

            UpgradeHelper.CheckUpgrades(this.Dispatcher);
        }
Example #2
0
 private void DoClickUpgrade(object sender, RoutedEventArgs e)
 {
     UpgradeHelper.CheckUpgrades(this.Dispatcher, true);
 }