Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 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?
Add Comment
Please, Sign In to add comment