コード例 #1
0
        // The main entry point.
        [STAThread] static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            AppDomain.CurrentDomain.UnhandledException += (o, e) => HandleException(e.ExceptionObject);
            Application.ThreadException += (o, e) => HandleException(e.Exception);

            try
            {
                if (syncOwned) // If this is a first executed instance of an application.
                {
                    CurrentContext = new RiftContext();

                    if (CurrentContext.Initialized)
                    {
                        Application.Run(CurrentContext);
                    }
                    else
                    {
                        throw new ContextException(Resources.ExceptionBadClient);
                    }
                }
                else
                {
                    // Single-instance application only: broadcast WM_NCSTART custom window message.
                    // This action shows (brings to front) the hidden main form of the first executed instance.
                    Win32.SendMessage(Win32.HWND_BROADCAST, Win32.WM_NCSTART, 0, 0);
                }
            }
            catch (Exception e) // Handles the unexpected exceptions.
            {
                HandleException(e);
            }
            finally
            {
                if (CurrentContext != null)
                {
                    CurrentContext.WriteSettings();
                    CurrentContext.Dispose();
                }

                Settings.Default.Save();

                if (syncOwned && instanceSync != null)
                {
                    instanceSync.ReleaseMutex();
                    instanceSync.Dispose();
                }

                if (restart)
                {
                    Process.Start(Application.ExecutablePath);
                }
            }
        }
コード例 #2
0
ファイル: App.cs プロジェクト: aggpys/Atreia-World
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            AppDomain.CurrentDomain.UnhandledException += (o, e) => HandleException(e.ExceptionObject);
            Application.ThreadException += (o, e) => HandleException(e.Exception);

            try
            {
                if (syncOwned) // If this is a first executed instance of an application.
                {
                    CurrentContext = new RiftContext();

                    if (CurrentContext.Initialized)
                        Application.Run(CurrentContext);
                    else
                        throw new ContextException(Resources.ExceptionBadClient);
                }
                else
                {
                    // Single-instance application only: broadcast WM_NCSTART custom window message.
                    // This action shows (brings to front) the hidden main form of the first executed instance.
                    Win32.SendMessage(Win32.HWND_BROADCAST, Win32.WM_NCSTART, 0, 0);
                }
            }
            catch (Exception e) // Handles the unexpected exceptions.
            {
                HandleException(e);
            }
            finally
            {
                if (CurrentContext != null)
                {
                    CurrentContext.WriteSettings();
                    CurrentContext.Dispose();
                }

                Settings.Default.Save();

                if (syncOwned && instanceSync != null)
                {
                    instanceSync.ReleaseMutex();
                    instanceSync.Dispose();
                }

                if (restart)
                    Process.Start(Application.ExecutablePath);
            }
        }