Monday, July 12, 2010

How to: Return a Value from a Task

Simple version from .net 4 Task library.

Task chicken = Task.Factory.StartNew(() => DoChicken());

//Do some chicken.

then when you chicken,

if(chicken.IsCompleted)
return(chicken.Result) //calling chicken.Result will hang until DoChicken finishes
else
chicken chicken.

No comments:

Post a Comment