public void UsingParallelFor() { var queue = new ConcurrentQueue<DataTriplet>(); Parallel.ForEach(_listA, a => { foreach (var b in _listB) { foreach (var c in _listC) { var item = new DataTriplet(a, b, c); queue.Enqueue(item); } } }); var list = queue.ToList(); }
private void Worker(Object stateInfo) { lock (stateInfo) { var state = (FromFromingWorkingState)stateInfo; var count = state.First + state.Count - 1; var list = new List<DataTriplet>(); for (int i = state.First; i < count; i++) { foreach (var b in state.SourceB) { foreach (var c in state.SourceC) { var item = new DataTriplet(state.SourceA[i], b, c); list.Add(item); } } } state.ResultList = list; if (state.DoneEvent != null) { state.DoneEvent.Set(); } } }
public void UsingFor() { var list = new List<DataTriplet>(); foreach (var a in _listA) { foreach (var b in _listB) { foreach (var c in _listC) { var item = new DataTriplet(a, b, c); list.Add(item); } } } }