Example #1
0
        /// <summary>
        /// 多线程切割剧本文件
        /// </summary>
        /// <param name="threadID">线程id</param>
        private void SplitHandler(object threadID)
        {
            int tid = (int)threadID;

            while (true)
            {
                FileInfo fi = null;
                lock (this.splitQueue)
                {
                    if (this.splitQueue.Count != 0)
                    {
                        fi = this.splitQueue.Dequeue();
                    }
                    else
                    {
                        break;
                    }
                }
                if (fi == null)
                {
                    continue;
                }
                lock (this.consoleMutex)
                {
                    Console.WriteLine("Spliting \"{0}\" At thread {1}", fi.Name, tid);
                }
                var resVec = new List <string>();
                try
                {
                    FileStream   fs = new FileStream(fi.FullName, FileMode.Open);
                    StreamReader sr = new StreamReader(fs);
                    while (!sr.EndOfStream)
                    {
                        resVec.Add(sr.ReadLine() + Environment.NewLine);
                    }
                    sr.Close();
                    fs.Close();
                    lock (this.consoleMutex)
                    {
                        Console.WriteLine("Compiling \"{0}\" At thread {1}", fi.Name, tid);
                    }
                    if (this.compileType == InterpreterType.DEBUG)
                    {
                        Pile pile       = new Pile();
                        var  yuriResult = new KeyValuePair <string, Scene>(
                            fi.Name.Split('.')[0], (Scene)pile.StartDash(resVec, fi.Name.Split('.')[0], this.compileType));
                        lock (this.SceneVector)
                        {
                            this.parseTreeStringVec.Add(pile.GetParsedTree());
                            this.SceneVector.Add(yuriResult);
                        }
                    }
                    else
                    {
                        Pile pile   = new Pile();
                        var  yuriIL = new KeyValuePair <string, string>(
                            fi.Name.Split('.')[0], (string)pile.StartDash(resVec, fi.Name.Split('.')[0], this.compileType));
                        lock (this.ILVector)
                        {
                            this.parseTreeStringVec.Add(pile.GetParsedTree());
                            this.ILVector.Add(yuriIL);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                    System.Windows.Forms.MessageBox.Show(ex.ToString());
                }
            }
            // 递增完成信号量
            lock (consoleMutex)
            {
                this.finishedThread++;
                Console.WriteLine("Thread {0} is Finished", tid);
            }
        }
Example #2
0
 /// <summary>
 /// 多线程切割剧本文件
 /// </summary>
 /// <param name="threadID">线程id</param>
 private void SplitHandler(object threadID)
 {
     int tid = (int)threadID;
     while (true)
     {
         FileInfo fi = null;
         lock (this.splitQueue)
         {
             if (this.splitQueue.Count != 0)
             {
                 fi = this.splitQueue.Dequeue();
             }
             else
             {
                 break;
             }
         }
         if (fi == null)
         {
             continue;
         }
         lock (this.consoleMutex)
         {
             Console.WriteLine(String.Format("Spliting \"{0}\" At thread {1}", fi.Name, tid));
         }
         List<string> resVec = new List<string>();
         try
         {
             FileStream fs = new FileStream(fi.FullName, FileMode.Open);
             StreamReader sr = new StreamReader(fs);
             while (!sr.EndOfStream)
             {
                 resVec.Add(sr.ReadLine() + Environment.NewLine);
             }
             sr.Close();
             fs.Close();
             lock (this.consoleMutex)
             {
                 Console.WriteLine(String.Format("Compiling \"{0}\" At thread {1}", fi.Name, tid));
             }
             if (this.compileType == InterpreterType.DEBUG)
             {
                 lock (this.SceneVector)
                 {
                     Pile pile = new Pile();
                     this.SceneVector.Add(new KeyValuePair<string, PackageScene>(
                         fi.Name.Split('.')[0], (PackageScene)pile.StartDash(resVec, fi.Name.Split('.')[0], this.compileType)));
                 }
             }
             else
             {
                 lock (this.ILVector)
                 {
                     Pile pile = new Pile();
                     this.ILVector.Add(new KeyValuePair<string, string>(
                         fi.Name.Split('.')[0], (string)pile.StartDash(resVec, fi.Name.Split('.')[0], this.compileType)));
                 }
             }
         }
         catch (Exception ex)
         {
             Console.WriteLine(ex.ToString());
         }
     }
     // 递增完成信号量
     lock (consoleMutex)
     {
         this.finishedThread++;
         Console.WriteLine(String.Format("Thread {0} is Finished", tid));
     }
 }