-1
我希望将两个BlockingCollection<>
传递给任务。我试图把它们放在一个对象数组中并传递它们,但它不起作用。谁能帮我这个?在那里我试图值传递的代码如下记载:将多个参数传递给任务
var lineHolders = new[]
{
new BlockingCollection<string>(linesCapacity),
new BlockingCollection<string>(linesCapacity),
new BlockingCollection<string>(linesCapacity),
new BlockingCollection<string>(linesCapacity)
};
var chunksHolder = new[]
{
new BlockingCollection<List<BsonDocument>>(chunksCapacity),
new BlockingCollection<List<BsonDocument>>(chunksCapacity)
};
for (var processors = 0; processors < 16; processors++)
{
var myLineHolder = lineHolders[processors%lineHolders.Length];
var myChunkHolder = chunksHolder[processors%chunksHolder.Length];
processorTaskArray[processors] = Task.Factory.StartNew((arg) =>
{
var lines = (BlockingCollection<string>) arg[0]; // compiler generates error here
var chunks = (BlockingCollection<List<BsonDocument>>) arg[1]; // compiler generates error here
// perform my work...
},
new object []
{
myLineHolder,
myChunkHolder
});
}
var lines = lineHolders [0]; – terrybozzio
特定任务的BlockingCollection行取决于循环索引处理器。不能做一个lineHolders [0]。 – displayName
什么是编译器错误? – Stefan