コード例 #1
0
ファイル: Form1.cs プロジェクト: OneWalkerCN/BDTranslater
        //开始翻译
        void StartTranslate()
        {
            // 获取参数
            q         = InputTxt.Text;
            appId     = APPID.Text;
            secretKey = SecrateTxt.Text;
            url       = APIAddress.Text;
            times     = int.Parse(TranslateTimes.Text);
            gaptime   = int.Parse(gapTime.Text);
            //设置进度条最大范围
            progress.Maximum = times;
            //新建线程以实现接口访问
            Thread th = new Thread(new ThreadStart(() =>
            {
                for (int i = 1; i <= times; i++)
                {
                    progress.Invoke(new Action(() => {
                        progress.Value = i;
                    }));
                    q = TranslateHelper.BDrequest(q, "zh", "en", appId, secretKey, url);
                    Thread.Sleep(gaptime);
                    q = TranslateHelper.BDrequest(q, "en", "zh", appId, secretKey, url);
                    Thread.Sleep(gaptime);
                }
                //进度完毕后重置
                progress.Invoke(new Action(() => {
                    progress.Value = 0;
                }));
                OutPutTxt.Invoke(new Action(() => {
                    OutPutTxt.Text = q;
                }));
            }));

            th.Start();
        }