我想使用TASK来运行并行活动。这个任务返回一个值。如何在任务中使用FUNC返回值?。我在Func处得到一个错误。
Task<Row> source = new Task<Row>(Func<Row> Check = () =>
{
var sFields = (
from c in XFactory.Slot("IdentifierA")
where c["SlotID"] == "A100"
select new
{
Field = c["Test"]
});
});
我将代码更改为
Task source = Task.Factory.StartNew(() =>
{
return
(from c in XFactory.Slot("IdentifierA")
where c["SlotID"] == "A100"
select new
{
Field = c["Test"]
});
}
);
答案 0 :(得分:3)
您的基本模式如下:
Task<Row> source = Task.Factory.StartNew<Row>(() => ...; return someRow; );
Row row = source.Result; // sync and exception handling