IdeaBlade DevForce 2010 Help Reference
Start(Func<CoroutineOperation,IEnumerable<INotifyCompleted>>,Action<CoroutineOperation>) Method
See Also  Example Send Feedback
IdeaBlade.EntityModel Assembly > IdeaBlade.EntityModel Namespace > Coroutine Class > Start Method : Start(Func<CoroutineOperation,IEnumerable<INotifyCompleted>>,Action<CoroutineOperation>) Method



coroutine
An iterator block containing asynchronous actions
completedHandler
Optional completion handler
Start serial execution of multiple asynchronous actions.

Syntax

Visual Basic (Declaration) 
Public Overloads Shared Function Start( _
   ByVal coroutine As Func(Of CoroutineOperation,IEnumerable(Of INotifyCompleted)), _
   Optional ByVal completedHandler As Action(Of CoroutineOperation) _
) As CoroutineOperation
Visual Basic (Usage)Copy Code
Dim coroutine As Func(Of CoroutineOperation,IEnumerable(Of INotifyCompleted))
Dim completedHandler As Action(Of CoroutineOperation)
Dim value As CoroutineOperation
 
value = Coroutine.Start(coroutine, completedHandler)

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

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.

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

© 2013 All Rights Reserved.