private IEnumerable <DataModel> StreamProcessPhase3(IEnumerable <DataModel> models) { foreach (var model in models) { DataModelHelper.ProcessPhase3(model); yield return(model); } }
public void Test1() { foreach (var model in GetModels()) { DataModelHelper.ProcessPhase1(model); DataModelHelper.ProcessPhase2(model); DataModelHelper.ProcessPhase3(model); } }
/// <summary> /// 串流處理:處理完一個物件的phase1,2,3才抓下一個物件 /// WIP只會有一個 /// </summary> private static void Demo2() { foreach (var model in GetModels()) { DataModelHelper.ProcessPhase1(model); DataModelHelper.ProcessPhase2(model); DataModelHelper.ProcessPhase3(model); } }
public static IEnumerable <DataModel> BlockedCollectionProcessPhase3(IEnumerable <DataModel> models) { BlockingCollection <DataModel> result = new BlockingCollection <DataModel>(BLOCKING_COLLECTION_CAPACITY); Task.Run(() => { foreach (var model in models) { DataModelHelper.ProcessPhase3(model); result.Add(model); } result.CompleteAdding(); }); return(result.GetConsumingEnumerable()); }
private static void Main(string[] args) { var json = JsonSerializer.Create(); var jsonreader = new JsonTextReader(Console.In); jsonreader.SupportMultipleContent = true; while (jsonreader.Read()) { var d = json.Deserialize <DataModel>(jsonreader); DataModelHelper.ProcessPhase3(d); json.Serialize(Console.Out, d); } }
private IEnumerable <DataModel> StreamAsyncProcessPhase3(IEnumerable <DataModel> models) { Task <DataModel> previous_result = null; foreach (var model in models) { if (previous_result != null) { yield return(previous_result.Result); } previous_result = Task.Run <DataModel>(() => { DataModelHelper.ProcessPhase3(model); return(model); }); } if (previous_result != null) { yield return(previous_result.GetAwaiter().GetResult()); } }
/// <summary> /// 批次處理:依序執行所有物件的phase1,再做所有的phase2,最後做所有的phase3 /// WIP與任務數量呈正比 /// </summary> private static void Demo1() { DataModel[] models = GetModels().ToArray(); foreach (var model in models) { DataModelHelper.ProcessPhase1(model); } foreach (var model in models) { DataModelHelper.ProcessPhase2(model); } foreach (var model in models) { DataModelHelper.ProcessPhase3(model); } }