private void TaskListCopy2(List <int> list2) { var pageList = new List <int>(); var x = new ConcurrentBag <int>(); var taskr = new TaskOptimizeByPaging(20); var taskList = new List <Task>(); for (int i = 0; i < 2; i++) { var task = Task.Run(() => { var newTs = taskr.GetListByPagination(list2); while (newTs.Count() > 0) { foreach (var item in newTs) { } newTs = taskr.GetListByPagination(list2); } }); taskList.Add(task); } Task.WaitAll(taskList.ToArray()); Console.WriteLine(@$ "list原集合中个数:{list2.Count()} TaskListCopy个数: {pageList.Distinct().Count()} "); //Console.WriteLine(@$"hs中个数:{hs.Count}"); Console.WriteLine(@$ "x中个数:{x.Count()}"); }
private void ListCopy(List <Student> list, List <int> list2) { TaskOptimizeByPaging.StopWatchAction(() => { var copylist = new List <Student>(); var copylist2 = new List <int>(); foreach (var item in list) { #region sql操作 copylist.Add(item); Thread.Sleep(1); foreach (var item2 in list2) { copylist2.Add(item2); Thread.Sleep(1); } #endregion } Console.WriteLine($"原集合中个数:{list.Count} ,ListCopyAfter个数: {copylist.Count()} "); }); }
private void TaskListCopy(List <Student> list, List <int> list2) { TaskOptimizeByPaging.StopWatchAction(() => { var pageList = new List <int>(); var taskr = new TaskOptimizeByPaging(20); var hs = new Hashtable(); var token = new CancellationTokenSource(); taskr.TaskRunWaitByPaging(list2, s => { hs.Add(s, ""); pageList.Add(s); // Console.WriteLine(s); }, token, null, 2 ); Console.WriteLine(@$ "list原集合中个数:{list2.Count()} TaskListCopy个数: {pageList.Distinct().Count()} "); //TaskListCopy个数: {pageList2.Distinct().Count()} "); Console.WriteLine(@$ "hs2中个数:{hs.Count}"); }); }