DevForce Help Reference
Start(Func<CoroutineOperation,IEnumerable<INotifyCompleted>>,Action<CoroutineOperation>) Method
Example 


An iterator block containing asynchronous actions
Optional completion handler
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
Remarks
Used to start serial execution of the asynchronous, and synchronous, actions within the specified iterator block. Asychronous actions within the block will cause subsequent actions to "wait" until each asynchronous operation yields when complete.

Use this overload of the Start method when your iterator accepts a CoroutineOperation as an argument. You can use the CoroutineOperation to track the prior operations within the iterator.

Example
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);
}
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

Coroutine Class
Coroutine Members
Overload List

Send Feedback