C# Parallel Task methods that return value using Func<>
I want to use TASK for running parallel activities.This task returns a value.How do i use a FUNC inside the task for returning a value?.I get an error at 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"]
});
});
I change my code to
Task source = Task.Factory.StartNew(() =>
{
return
开发者_如何学运维 (from c in XFactory.Slot("IdentifierA")
where c["SlotID"] == "A100"
select new
{
Field = c["Test"]
});
}
);
Your basic pattern would look like:
Task<Row> source = Task.Factory.StartNew<Row>(() => ...; return someRow; );
Row row = source.Result; // sync and exception handling
精彩评论