Пример #1
0
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            WebServer ws = null;

            var ticket = new Ticket("/tvmaid/mutex/main");

            try
            {
                if (ticket.GetOwner(60 * 1000) == false)
                {
                    ticket = null;
                    throw new AppException("時間内に二重起動が解消されませんでした。");
                }

                Log.Write(AppVer);
                LoadDef();

                //先に読み込んでおく
                GenreConv.GetInstance();
                TextConv.GetInstance();

                if (args.Length == 1 && args[0] == "-tunerupdate")
                {
                    UpdateTuner();
                }

                TaskList.StartNew(() => { RecTimer.GetInstance().Start(); });
                ws = new WebServer();
                TaskList.StartNew(() => { ws.Start(); });

                TunerMon.GetInstance();
                Application.Run(new Tasktray());
            }
            catch (Exception e)
            {
                MessageBox.Show("このエラーは回復できないため、アプリケーションは終了します。[詳細]" + e.Message, Logo);
            }
            finally
            {
                if (ws != null)
                {
                    ws.Dispose();
                }
                RecTimer.GetInstance().Dispose();

                if (StateDef != null)
                {
                    StateDef.Save();
                }

                //スレッド終了待ち
                int i = 0;
                while (TaskList.GetInstance().IsFinish() == false)
                {
                    System.Threading.Thread.Sleep(100);
                    i++;
                    if (i > 300)
                    {
                        break;
                    }
                }
                if (ticket != null)
                {
                    ticket.Dispose();
                }
            }
        }
Пример #2
0
        public static void StartNew(Action action)
        {
            var task = Task.Factory.StartNew(action);

            TaskList.GetInstance().Add(task);
        }
Пример #3
0
        public static void StartNew(Action <object> action, object state)
        {
            var task = Task.Factory.StartNew(action, state);

            TaskList.GetInstance().Add(task);
        }
Пример #4
0
        public void Start()
        {
            using (var sql = new Sql(true))
            {
                //チューナ毎のスレッドを起動
                sql.Text = @"select * from tuner";
                using (var t = sql.GetTable())
                {
                    while (t.Read())
                    {
                        var tuner = new Tuner(t);
                        TaskList.StartNew(StartThread, tuner);
                    }
                }

                //番組表取得時間を初期化
                nextEpgTime = DateTime.Now.Date;
                nextEpgTime = nextEpgTime.AddHours(Program.UserDef["epg.autoupdate.hour"].ToInt());

                //メインループ
                //番組表取得、自動予約の監視
                while (stop == false)
                {
                    try
                    {
                        if (nextEpgTime <= DateTime.Now)
                        {
                            //古い予約と番組情報の削除
                            //先に予約を消すこと(予約に番組情報への参照があるため)
                            ClearnRecord(sql);
                            ClearnEvent(sql);

                            //番組表取得1時間以内なら実行
                            if (nextEpgTime + TimeSpan.FromHours(1) >= DateTime.Now)
                            {
                                epg = true;
                            }
                            //次回を翌日にセット
                            nextEpgTime = DateTime.Now.Date;
                            nextEpgTime = nextEpgTime.AddDays(1);   //翌日
                            nextEpgTime = nextEpgTime.AddHours(Program.UserDef["epg.autoupdate.hour"].ToInt());
                        }

                        //番組表取得
                        if (epg)
                        {
                            epgQu.Enqu();
                            epg = false;
                        }

                        StartAutoRecord(sql);   //自動予約

                        Thread.Sleep(mainSleep);
                    }
                    catch (Exception e)
                    {
                        Log.Write("エラーが発生しました。[詳細] " + e.Message);
                    }
                }
            }
        }