Created
October 29, 2010 18:18
-
-
Save anonymous/654056 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Looking for basically this functionality: | |
Action cont1 = ...; | |
Action cont2 = ...; | |
var scheduler = TaskScheduler.FromCurrentSynchronizationContext(); | |
Task.Factory.StartNew(() => | |
{ | |
if (some-synchronous-computation()) | |
Task.Factory.StartNew(cont1, ..., scheduler); | |
else | |
Task.Factory.StartNew(cont2, ..., scheduler); | |
}); | |
// But then without the lambda needing to close over the continuation delegates and especially the TaskScheduler. | |
// That is to say, I want something much more like this: | |
var task = Task.Factory.StartNew(() => | |
{ | |
if (some-synchronous-computation()) | |
throw new Exception(); | |
else | |
return; | |
}); | |
task.ContinueWith(cont1, TaskContinuationOptions.OnlyOnFaulted, | |
TaskScheduler.FromCurrentSynchronizationContext()); | |
task.ContinueWith(cont2, TaskContinuationOptions.NotOnFaulted, | |
TaskScheduler.FromCurrentSynchronizationContext()); | |
// But then without the arbitrary exception throwing that really has no place in the code. | |
// What would you suggest as an elegant way to deal with this? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment