예제 #1
0
        public static void CUIMain(Action <ArgsReader> mainFunc)
        {
            try
            {
                WriteLog = message => Console.WriteLine("[" + DateTime.Now + "] " + message);

                SelfFile = Assembly.GetEntryAssembly().Location;
                SelfDir  = Path.GetDirectoryName(SelfFile);

                WorkingDir.Root = WorkingDir.CreateProcessRoot();

                ArgsReader = GetArgsReader();

                mainFunc(ArgsReader);

                WorkingDir.Root.Delete();
                WorkingDir.Root = null;
            }
            catch (Exception e)
            {
                WriteLog(e);

                Console.WriteLine("Press ENTER key.");
                Console.ReadLine();
            }
        }
예제 #2
0
        public static void GUIMain(Func <Form> getMainForm)
        {
            Application.ThreadException += new ThreadExceptionEventHandler(ApplicationThreadException);
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomainUnhandledException);
            SystemEvents.SessionEnding += new SessionEndingEventHandler(SessionEnding);

            //WriteLog = message => { };

            SelfFile = Assembly.GetEntryAssembly().Location;
            SelfDir  = Path.GetDirectoryName(SelfFile);

            Mutex procMutex = new Mutex(false, APP_IDENT);

            if (procMutex.WaitOne(0))
            {
                if (GlobalProcMtx.Create(APP_IDENT, APP_TITLE))
                {
                    CheckSelfFile();
                    Directory.SetCurrentDirectory(SelfDir);
                    CheckLogonUserAndTmp();

                    WorkingDir.Root = WorkingDir.CreateProcessRoot();

                    ArgsReader = GetArgsReader();

                    // core >

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

                    // < core

                    WorkingDir.Root.Delete();
                    WorkingDir.Root = null;

                    GlobalProcMtx.Release();
                }
                procMutex.ReleaseMutex();
            }
            procMutex.Close();
        }