public void ParseUsedTextureDatas() { Console.WriteLine("Start Parsing Texture List."); string textureFilePath; while (res.ParseNextTextureFilePath(out textureFilePath)) { Console.WriteLine(" Find used Texture : {0}.", textureFilePath); SubTaskParam param = new SubTaskParam(); param.TextureFilePath = textureFilePath; param.TaskGroup = this; //Task<ImageFileData> readImageFileTask = Task <ImageFileData> .Factory.StartNew(arg => { SubTaskParam p = arg as SubTaskParam; MaterialTaskGroup argTaskGroup = param.TaskGroup; Console.WriteLine(" Read Image File : {0}", p.TextureFilePath); ImageFileData imgFileData = res.ReadFileData <ImageFileData>(); return(imgFileData); }, param, CTS.Token, TaskCreationOptions.AttachedToParent, SchedulerIO) .ContinueWith((antecedent, arg) => { SubTaskParam p = arg as SubTaskParam; ImageFileData imgFileData = antecedent.Result as ImageFileData; Console.WriteLine(" Parse Image Data : {0}", p.TextureFilePath); ImageData imgData = res.ParseImageInfo(imgFileData); return(imgData); }, param, CTS.Token, TaskContinuationOptions.AttachedToParent, TaskScheduler.Default) .ContinueWith((antecedent, arg) => { SubTaskParam p = arg as SubTaskParam; ImageData imgFileData = antecedent.Result as ImageData; Console.WriteLine(" Create Texture from Image Data : {0}", p.TextureFilePath); Texture texture = res.CreateTexture(p.TextureFilePath, imgFileData); textures.Add(texture); }, param, CTS.Token, TaskContinuationOptions.AttachedToParent, SchedulerMain); } }
static void TaskGraphLoadingMaterial() { MaterialTaskGroup taskGroup = new MaterialTaskGroup(); Task readMaterialFileDataTask = Task.Factory.StartNew(arg => { MaterialTaskGroup argTaskGroup = arg as MaterialTaskGroup; argTaskGroup.ReadMaterialData(); }, taskGroup, taskGroup.CTS.Token, TaskCreationOptions.None, taskGroup.SchedulerIO); Task parseMaterialFileDataTask = readMaterialFileDataTask.ContinueWith((antecedent, arg) => { MaterialTaskGroup argTaskGroup = arg as MaterialTaskGroup; argTaskGroup.ParseMaterialData(); }, taskGroup, taskGroup.CTS.Token, TaskContinuationOptions.None, TaskScheduler.Default); Task parseUsedTextureTask = readMaterialFileDataTask.ContinueWith((antecedent, arg) => { MaterialTaskGroup argTaskGroup = arg as MaterialTaskGroup; argTaskGroup.ParseUsedTextureDatas(); }, taskGroup, taskGroup.CTS.Token, TaskContinuationOptions.None, TaskScheduler.Default); Task JoinTask = Task.WhenAll(new List <Task> { parseMaterialFileDataTask, parseUsedTextureTask }); taskGroup.finalAssmebleTask = JoinTask.ContinueWith((antecedent, arg) => { MaterialTaskGroup argTaskGroup = arg as MaterialTaskGroup; argTaskGroup.AssembleTexutureIntoMaterial(); }, taskGroup, taskGroup.CTS.Token, TaskContinuationOptions.None, taskGroup.SchedulerMain); Task.WaitAll(taskGroup.finalAssmebleTask); taskGroup.ShowMaterial(); Console.WriteLine("Loading Finished."); }