Start serial execution of multiple asynchronous actions.
Syntax
Parameters
- coroutine
- An iterator block containing asynchronous actions
- completedHandler
- Optional completion handler
Return Value
A CoroutineOperation representing this operation
Example
C# | Copy Code |
---|
public void CoroutineSample2() {
Coroutine.Start(Sample2Actions, (op) => {
SaveResult sr = op.Result as SaveResult;
MessageBox.Show("Save count = " + sr.SavedEntities.Count().ToString());
});
}
private IEnumerable<INotifyCompleted> Sample2Actions(CoroutineOperation coop) {
// Sample showing use of the CoroutineOperation during processing,
// and returning a final result to the Coroutine.
var mgr = new DomainModelEntityManager();
// Get a few customers
yield return mgr.Customers.Take(2).ExecuteAsync();
// See what we got.
var custs = (coop.Notifications.Last() as EntityQueryOperation<Customer>).Results;
// Now get a few employees
yield return mgr.Employees.Take(3).ExecuteAsync();
// See what we've got
var emps = (coop.Notifications.Last() as EntityQueryOperation<Employee>).Results;
// We can also make changes and save.
emps.ForEach(e => e.Notes = "Updated at " + DateTime.Now.ToString());
yield return mgr.SaveChangesAsync();
// Let's return the final result too.
SaveResult sr = (coop.Notifications.Last() as EntitySaveOperation).SaveResult;
yield return Coroutine.Return(sr);
} |
Remarks
Requirements
Target Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family
See Also