这是我的播放按钮单击事件,我想从我的每个文件中获取Listbox
并执行操作:
private void btnPlay_Click(object sender, EventArgs e)
{
MyClass calss = new MyClass();
Task.Factory.StartNew(() =>
{
var files = listBoxFiles.Items.Count;
Parallel.ForEach(files ,
new ParallelOptions
{
MaxDegreeOfParallelism = 10 // limit number of parallel threads here
},
file =>
{
class.sendBuffer(file, selectedAdapter.PacketDevice, getSpeed(), capinfos.packets);
});
}).ContinueWith(
t => { /* when all files processed. Update your UI here */ }
, TaskScheduler.FromCurrentSynchronizationContext() // to ContinueWith (update UI) from UI thread
);
}
我得到了我不知道如何解决的错误Parallel.ForEach
:
错误1方法'System.Threading.Tasks.Parallel.ForEach(System.Collections.Generic.IEnumerable,System.Threading.Tasks.ParallelOptions,System.Action)的类型参数)' 不能从用法中推断出来。尝试明确指定类型参数。