DevForce Help Reference
Fail Method (Coroutine)
Example 


The exception to return to caller
If true you will not need to call MarkErrorAsHandled in a completion handler
Indicates a cancelled operation
Used to force a failed or cancelled return from within a Coroutine iterator.
Syntax
'Declaration
 
Public Shared Function Fail( _
   ByVal error As Exception, _
   Optional ByVal isErrorHandled As Boolean, _
   Optional ByVal cancelled As Boolean _
) As CoroutineOperation
'Usage
 
Dim error As Exception
Dim isErrorHandled As Boolean
Dim cancelled As Boolean
Dim value As CoroutineOperation
 
value = Coroutine.Fail(error, isErrorHandled, cancelled)

Parameters

error
The exception to return to caller
isErrorHandled
If true you will not need to call MarkErrorAsHandled in a completion handler
cancelled
Indicates a cancelled operation
Remarks
Use Fail within an iterator to force an exit from further processing within the iterator. The completion handler will receive indication of the error or cancellation.
Example
public void SampleCoroutineWithFail() {
  var op = Coroutine.Start(CoroutineWithFail);
  op.Completed += (s, e) => {
    if (e.HasError) {
       MessageBox.Show(e.Error.Message);
    }
  };
}

public IEnumerable<INotifyCompleted> CoroutineWithFail() {
  // Do 1 operation
  yield return _entityManager.Customers.Take(3).ExecuteAsync();
  
  // Let's fail now, why not?
  yield return Coroutine.Fail(new Exception("failed here"), true);

  // This operation will never be run because of the fail above.
  var op2 = _em1.Areas.Take(2).ExecuteAsync();
}
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

Send Feedback