Exemple #1
0
        public static void CorrectMFC(string label)
        {
            var cells = from cell in Root.GetDirectories()
                        where ConfigInfo.NameList.ContainsKey(cell.Name)
                        select new DirectoryInfo($"{cell.FullName}\\{label}\\MFC");
            // 编译到运行的管线
            var pipeline = new Queue <string>();
            // 设置编译线程
            Action compileEvent = async() => {
                foreach (var cell in cells)
                {
                    var compiler      = new Compiler();
                    var compileResult = await compiler.BuildMFC(cell);

                    if (compileResult.ExecFile != null)
                    {
                        lock (pipeline) pipeline.Enqueue(compileResult.ExecFile.FullName);
                    }
                }
                lock (pipeline) pipeline.Enqueue("end");
            };
            // 设置运行线程
            Action executeEvent = async() => {
                var executableFile = "start";
                var redPen         = new RedPen();
                while (executableFile != "end")
                {
                    if (File.Exists(executableFile))
                    {
                        redPen.CorrectMFC(new FileInfo(executableFile));
                    }
                    await Task.Run(() => { while (pipeline.Count != 0)
                                           {
                                               ;
                                           }
                                   });

                    executableFile = pipeline.Dequeue();
                }
            };

            Parallel.Invoke(compileEvent, executeEvent);
        }