Пример #1
0
        private void btnManual_Click(object sender, EventArgs e)
        {
            switch (run_status_label.Text)
            {
            case "尚未啟動":

                run_status_label.Text      = "啟動中...";
                run_status_label.ForeColor = Color.Green;
                threads["RUN_UPLOAD"]      = new Thread(() =>
                {
                    while (true)
                    {
                        setStatusBar("同步開始...", 0);
                        //上傳
                        run_upload();
                        setStatusBar("閒置中...", 0);
                        //每 10 分鐘傳一次
                        //Thread.Sleep(10 * 60);
                        Thread.Sleep(Convert.ToInt32(my.getSystemKey("LOOP_MINUTE")) * 60 * 1000);
                        //Thread.Sleep(30 * 1000);
                    }
                });
                threads["RUN_UPLOAD"].Start();

                break;

            case "啟動中...":
                run_status_label.Text      = "尚未啟動";
                run_status_label.ForeColor = Color.Red;
                setStatusBar("同步停止...", 0);
                if (threads.ContainsKey("RUN_UPLOAD"))
                {
                    threads["RUN_UPLOAD"].Abort();
                    threads["RUN_UPLOAD"] = null;
                }
                break;
            }
        }