views:

41

answers:

1

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"]
            });
            }
            );
A: 

Your basic pattern would look like:

 Task<Row> source = Task.Factory.StartNew<Row>(() => ...; return someRow;  );
 Row row = source.Result; // sync and exception handling
Henk Holterman