小编use*_*446的帖子

跟踪Parallel Foreach线程

我目前正在编写一个简单的WPF文件复制应用程序,它可以并行复制文件.到目前为止它很棒!它做我想做的一切.操作的内容在以下代码块中:

Parallel.ForEach(Directory.GetFiles(dir).ToList(), file =>
{
    _destDetail.CurrOp = string.Format("Copying file: {0}", Path.GetFileName(file));
    File.Copy(file, file.Replace(_destDetail.Source, _destDetail.Dest), true);
    if (_destDetail.Progress < _destDetail.MaxProgress)
        _destDetail.Progress++;
});
Run Code Online (Sandbox Code Playgroud)

我也可以实现ParallelOptions并将最大线程数限制为4,但我想知道是否有办法准确地跟踪每个线程在这种情况下会做什么?

例如,假设我的UI的一部分专用于复制操作的当前"状态".我希望有4行Grid,每行有一个特定的线程和当前正在复制的文件.

我知道我可以使用Interlocked以操纵是外部变量的Parallel循环,但我怎么会跟踪线程特定变量从内部的中Parallel环,并使用这些变量来保持UI最新哪个线程正在哪个文件?

c# parallel-processing wpf multithreading

5
推荐指数
1
解决办法
825
查看次数

停止ComboBox从滚动到顶部

WPF,有没有办法ComboBox在用户到达列表末尾时禁用自动滚动的滚动行为到列表的顶部?我宁愿列表停留在最后,用户必须手动滚动回到顶部.

以下是XAML ComboBox:

 <ComboBox x:Name="CellProviderCombo" HorizontalAlignment="Left" Height="65" Margin="14,405,0,0" VerticalAlignment="Top" Width=" 327" Header="Cell Provider" PlaceholderText="Choose Cell Provider" DataContext="{StaticResource GlobalVars}" ItemsSource="{Binding GlobalShopInfo.CellProviders}" DisplayMemberPath="Name" SelectedValuePath="Name" IsDoubleTapEnabled="False"/>
Run Code Online (Sandbox Code Playgroud)

正如我所说,如果你滚过组合框中的最后一个元素,它只是从底部开始,滚动条自动回到顶部.

c# wpf

0
推荐指数
1
解决办法
614
查看次数

标签 统计

c# ×2

wpf ×2

multithreading ×1

parallel-processing ×1