コード例 #1
0
 public static void CloseLoadingScreen()
 {
     //if the operation is too short, the _ls is not correctly initialized and it throws
     //a null error
     if (_ls != null && _ls.InvokeRequired)
     {
         _ls.Invoke(new MethodInvoker(CloseLoadingScreen));
     }
     else
     {
         if (_shown)
         {
             //if the operation is too short and the thread is not started
             //this would close the main thread
             _shown = false;
             Application.ExitThread();
         }
         if (_LoadingScreenThread != null)
         {
             _LoadingScreenThread.Interrupt();
         }
         if (_ls != null)
         {
             _ls.Close();
             _ls.Dispose();
         }
         _LoadingScreenThread = null;
     }
 }
コード例 #2
0
 public static void CloseLoadingScreen()
 {
     //if the operation is too short, the _ls is not correctly initialized and it throws
     //a null error
     if (_ls != null && _ls.InvokeRequired)
     {
         _ls.Invoke(new MethodInvoker(CloseLoadingScreen));
     }
     else
     {
         if (_shown)
         {
             //if the operation is too short and the thread is not started
             //this would close the main thread
             _shown = false;
             Application.ExitThread();
         }
         if (_LoadingScreenThread != null)
         {
             _LoadingScreenThread.Interrupt();
         }
         //this check prevents the appearance of the loader
         //or its closing/disposing if shown
         //have not found the answer
         //if (_ls !=null)
         //{
         _ls.Close();
         _ls.Dispose();
         //}
         _LoadingScreenThread = null;
     }
 }
コード例 #3
0
 public static void CloseLoadingScreen()
 {
     try
     {
         loadingScreen.DialogResult = DialogResult.OK;
         loadingScreen.Close();
         loadingScreen.Dispose();
         loadingScreen = null;
     }
     catch
     { }
 }
コード例 #4
0
        private static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            DateTime startTime = DateTime.Now;

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // Update settings from previous version
            if (Settings.Default.UpgradeRequired)
            {
                Settings.Default.Upgrade();
                Settings.Default.UpgradeRequired = false;
                Settings.Default.Save();
            }

            Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(Settings.Default.SelectedCulture);
            log.Debug("Set culture to " + Thread.CurrentThread.CurrentUICulture);

            // code to ensure that only one copy of the software is running.
            Mutex          mutex;
            string         strLoc    = Assembly.GetExecutingAssembly().Location;
            FileSystemInfo fileInfo  = new FileInfo(strLoc);
            string         sExeName  = fileInfo.Name;
            string         mutexName = "Global\\" + sExeName;

            try
            {
                mutex = Mutex.OpenExisting(mutexName);

                //since it hasn’t thrown an exception, then we already have one copy of the app open.
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false);
                String   appTitle   = ((AssemblyProductAttribute)attributes[0]).Product;

                MessageBox.Show(StringResources.ProgramInstanceAlreadyRunning, appTitle, MessageBoxButtons.OK, MessageBoxIcon.Information);
                Environment.Exit(0);
            }
            catch
            {
                //since we didn’t find a mutex with that name, create one
                mutex = new Mutex(true, mutexName);
            }

            // Check Data directory
            if (SettingsUtil.SetDefaultDataDirIfEmpty(Settings.Default))
            {
                Settings.Default.Save();
            }

            SongManager songManager = new SongManager(SettingsUtil.GetSongDirPath(Settings.Default));

            ImageManager imgManager = new ImageManager(SettingsUtil.GetImageDirPath(Settings.Default), SettingsUtil.GetThumbDirPath(Settings.Default))
            {
                DefaultThumbSize  = Settings.Default.ThumbSize,
                DefaultEmptyColor = Settings.Default.ProjectionBackColor
            };

            BibleManager bibleManager = new BibleManager(SettingsUtil.GetBibleDirPath(Settings.Default));

            if (Settings.Default.ShowLoadingScreen)
            {
                LoadingScreen ldg = new LoadingScreen(songManager, imgManager);
                ldg.SetLabel("PraiseBase Presenter wird gestartet...");
                ldg.Show();

                ldg.SetLabel("Prüfe Miniaturbilder...");
                imgManager.CheckThumbs(false);

                ldg.SetLabel("Lade Liederdatenbank...");
                songManager.Reload();

                GC.Collect();
                ldg.Close();
                ldg.Dispose();
            }
            else
            {
                imgManager.CheckThumbs(false);
                songManager.Reload();
                GC.Collect();
            }

            log.Debug(@"Loading took " + (DateTime.Now - startTime).TotalSeconds + @" seconds!");

            string setlistFile = null;
            string songFile    = null;

            // Detect if program is called with a setlist file as argument
            if (args.Length == 1)
            {
                if (File.Exists((args[0])))
                {
                    string ext = Path.GetExtension(args[0]);
                    if (ext == "." + SetlistWriter.FileExtension)
                    {
                        setlistFile = args[0];
                    }
                    else
                    {
                        songFile = args[0];
                    }
                }
            }

            Form mw;

            if (songFile != null)
            {
                mw = new SongEditor(Settings.Default, imgManager, songFile);
            }
            else
            {
                mw = new MainWindow(songManager, imgManager, bibleManager, setlistFile);
            }
            Application.Run(mw);
            GC.KeepAlive(mutex);
        }