We've been using AsyncSerialTask for quite a while now, but what has never been clear to me is how to stop the task prematurely when a problem occurs. Consider the following pseudo-code:
AsyncSerialTask.Create()
.AddExceptionHandler((x) =>
{
MessageBox.Show(x.Exception);
}
.AddAsyncAction((a) => CheckForDuplicateName(a, nameToCheck))
.AddAction((b) =>
{
if (b.HasError)
throw b.Error;
// Results indicate an entity with the same name already exists in the database.
if (a.Results.Count() > 0)
throw new Exception("Name is not unique");
}
.AddAsyncAction*
.AddAction*
.AddAsyncSave*
.Execute(null, (a) => { });
Now, obviously the code in AddAction(b) could probably be done internally to CheckForDuplicateName, but I broke it out for demonstration. We want to stop the task from continuing if the name is a duplicate, so we check the results and throw a new exception, allowing the task ExceptionHandler to handle the problem. This works, but the debugger likes to inform us that the exception is not handled when we do this (even though it is). Optionally we could pass around a task process status in the event args and short circuit things that way too. Is there another option? What is the preferred way to handle this?