Created
October 8, 2014 08:43
-
-
Save james-world/ee4d9c04765263070671 to your computer and use it in GitHub Desktop.
How to watch a bad task and not fall into the cancellation token trap!
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
using System; | |
using System.Reactive.Linq; | |
using System.Reactive.Threading.Tasks; | |
using System.Threading; | |
using System.Threading.Tasks; | |
namespace AsyncEvil | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var evt = new AutoResetEvent(false); | |
var task = Task.Run(() => | |
{ | |
evt.WaitOne(); | |
}); | |
task.ToObservable() | |
.Timeout(TimeSpan.FromSeconds(5)) | |
.Subscribe(_ => { }, ex => Console.WriteLine(ex.Message)); | |
Console.WriteLine("Waiting..."); | |
Console.ReadKey(true); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment