예제 #1
0
 public void add(qaacTask t)
 {
     lock (lockObj)
     {
         // 在队列中添加
         // 此处不判断队列是否为满,请在上层对象中加以判断
         this.tQueue[this.rear] = t;
         this.rear = (this.rear + 1) % (this.max + 1);
         this.length++;  // 长度+1
     }
 }
예제 #2
0
 public void removeTask(qaacTask t, bool isfailed)
 {
     // 移动到指定的队列
     if (!isfailed)
     {
         this.completedQueue.add(t);
     }
     else
     {
         this.failedQueue.add(t);
     }
 }
예제 #3
0
        public qaacTask getTask()
        {
            // 取一个任务(取出后该任务即从队列中移除了)
            qaacTask t = this.waitingQueue.pop();

            if (t != null)
            {
                // 赋config值
                //t.setConfig();

                return(t);
            }
            return(t);  // 如果未取得task,返回null,交job处理
        }
예제 #4
0
        public qaacTask pop()
        {
            lock (lockObj)  // 锁定,不允许其他线程同时运行这段代码
            {
                // 取出队首Task并且从队列中移除
                if (this.front == this.rear)
                {
                    return(null);  // 队列为空返回null由运行池处理
                }
                else
                {
                    qaacTask x = this.tQueue[this.front];
                    this.front = (this.front + 1) % (this.max + 1);

                    this.length--;  // 长度-1
                    return(x);
                }
            }
        }
예제 #5
0
        private void runTask(qaacTask t, Process process)
        {
            // MediaInfo读取音频时长
            MediaInfo MI = new MediaInfo();
            string    duration;

            MI.Open(t.filePath);
            duration = MI.Get(StreamKind.Audio, 0, 69);
            //MessageBox.Show(duration);
            if (!String.IsNullOrWhiteSpace(duration))
            {
                rsForm.setTime("0/" + duration);
            }

            // 运行
            process = new System.Diagnostics.Process();

            process.StartInfo.FileName = "cmd";

            // 必须禁用操作系统外壳程序
            process.StartInfo.UseShellExecute        = false;
            process.StartInfo.CreateNoWindow         = true;
            process.StartInfo.RedirectStandardError  = true;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardInput  = true;

            process.ErrorDataReceived  += new DataReceivedEventHandler(OutputHandler);
            process.OutputDataReceived += new DataReceivedEventHandler(OutputHandler);
            process.Start();

            cmdCode c   = new cmdCode(t.filePath, commonCode);
            string  cmd = c.cmdCodeGenerate();

            process.StandardInput.WriteLine(cmd);

            this.rsForm.setStatusBarFilesCountLabel(this.finishedNum, this.num);

            this.PIDs[0] = process.Id;

            process.BeginErrorReadLine();
            process.BeginOutputReadLine();
        }
예제 #6
0
        private void threadRun(int threadIndex)
        {
            qaacTask t = rp.getTask();
            qaacTask next;

            for (int i = 0; i < this.num; i++)
            {
                if (i != 0)
                {
                    rp.removeTask(t, false);            // false表示成功完成编码没有失败
                }
                this.isfinished[threadIndex] = false;
                this.rsForm.setStopBtnState(true);
                this.runTask(t, this.rsForm.process);

                while (this.isfinished[threadIndex] == false)
                {
                    Thread.Sleep(500);
                }

                //string lastCommandLineOutput = "qaacGUI v0.1";
                //while (!String.Equals(lastCommandLineOutput, this.rsForm.getCommandLine())) // 状态指示未完成时一直在此等待
                //{
                //    lastCommandLineOutput = this.rsForm.getCommandLine();
                //    Thread.Sleep(500);
                //}

                next = rp.getTask();                    // get之后任务已从运行池的等待队列中pop出了,无需再次get
                //MessageBox.Show(next.printTask());
                if (next == null)
                {
                    rp.removeTask(t, false);
                    break;
                }
                t = next;
            }
        }