Ejemplo n.º 1
0
        private static void Main(string[] args)
        {
            List <Task> tasks = new List <Task>();
            WebServer   ws    = null;

            // mark10als
            // Log.Write(AppData.AppName + " " + AppData.AppVersion);
            Log.Write(AppData.AppName + " " + AppData.AppVersion + " " + AppData.AppMod);
            Ticket ticket = new Ticket("/tvmaid/mutex/main");

            try
            {
                if (!ticket.GetOwner(10000))
                {
                    ticket = null;
                    throw new Exception("時間内に二重起動が解消されませんでした。");
                }
                Program.LoadDef();
                if (MainDef.GetInstance()["debug"] == "1")
                {
                    Log.GetInstance().SetLevel(1);
                    Log.Write("debug mode 1 に設定しました。");
                }
                Program.CopyPlugin();
                if (args.Length == 1 && args[0] == "-tunerupdate")
                {
                    Program.UpdateTuner();
                }
                Task item = Task.Factory.StartNew(() =>
                {
                    RecTimer.GetInstance().Run();
                }, TaskCreationOptions.AttachedToParent);
                tasks.Add(item);
                ws   = new WebServer();
                item = Task.Factory.StartNew(() =>
                {
                    ws.Start();
                }, TaskCreationOptions.AttachedToParent);
                tasks.Add(item);
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new TunerMon());
            }
            catch (Exception ex)
            {
                string str = ex.Message + ex.StackTrace;
                MessageBox.Show("このエラーは回復できないため、アプリケーションは終了します。[詳細]" + str, AppData.AppName);
            }
            finally
            {
                if (ws != null)
                {
                    ws.Dispose();
                }
                RecTimer.GetInstance().Dispose();
                ExitForm form = new ExitForm(30);
                Task.Factory.StartNew(delegate
                {
                    Task.WaitAll(tasks.ToArray(), 30000);
                }).ContinueWith(delegate(Task _)
                {
                    form.Close();
                }, TaskScheduler.FromCurrentSynchronizationContext());
                form.ShowDialog();
                if (ticket != null)
                {
                    ticket.Dispose();
                }
                Program.StartNextProcess();
            }
        }