Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将列表分组_C#_Multithreading - Fatal编程技术网

C# 将列表分组

C# 将列表分组,c#,multithreading,C#,Multithreading,我贴了一个问题 得到 如何分别访问用户1或用户2的组而不是foreach 在上面的代码中,它将对它们进行排序和打印。我想按组访问它们 lines.AsParallel().Select(x => x.TheUser) 应该向您返回用户的IEnumerable…您真的应该使用Microsoft的反应式框架。只需获取“Rx Main”,然后您就可以执行以下操作: var query = from grp in lines.GroupBy(line => line.TheUs

我贴了一个问题

得到

如何分别访问用户1或用户2的组而不是foreach

在上面的代码中,它将对它们进行排序和打印。我想按组访问它们

lines.AsParallel().Select(x => x.TheUser)  

应该向您返回用户的IEnumerable…

您真的应该使用Microsoft的反应式框架。只需获取“Rx Main”,然后您就可以执行以下操作:

var query =
    from grp in lines.GroupBy(line => line.TheUser).ToObservable()
    from line in grp.ToObservable()
    from output in Observable.Start(() => /* Do lengthy process here */)
    select new { line, output };

query.Subscribe(result => { /* get the results here */ });
现在,为了让我证明这是可行的:

var query =
    from grp in Enumerable.Range(0, 20).GroupBy(x => x % 5).ToObservable()
    from line in grp.ToObservable()
    from tid in Observable.Start(() => System.Threading.Thread.CurrentThread.ManagedThreadId)
    select new { line, tid };
当使用
query.Subscribe(x=>{…})
运行时,它会给出这种输出:


您可以看到,
ManagedThreadId
更改了输入值,因此处理是并行进行的。

您需要更清楚地了解实际需要做什么。我想按组访问它们意味着什么?您想对分组执行什么操作?
var query =
    from grp in Enumerable.Range(0, 20).GroupBy(x => x % 5).ToObservable()
    from line in grp.ToObservable()
    from tid in Observable.Start(() => System.Threading.Thread.CurrentThread.ManagedThreadId)
    select new { line, tid };