Skip to content

Instantly share code, notes, and snippets.

@marek-safar
Created August 19, 2011 13:42
Show Gist options
  • Save marek-safar/1156815 to your computer and use it in GitHub Desktop.
Save marek-safar/1156815 to your computer and use it in GitHub Desktop.
using System;
using System.Threading;
using System.Threading.Tasks;
class C
{
public static void Main ()
{
var tsc = new TaskCompletionSource<int> ();
Thread t1 = new Thread (() => {
while (true) {
tsc.TrySetCanceled ();
}
});
/*
Thread t2 = new Thread (() => {
while (true) {
tsc.TrySetResult (2);
}
});
*/
Thread t3 = new Thread (() => {
while (true) {
tsc.TrySetException (new NotImplementedException ());
}
});
t1.Start ();
//t2.Start ();
t3.Start ();
while (true) {
t1.Suspend ();
// t2.Suspend ();
t3.Suspend ();
tsc = new TaskCompletionSource<int> ();
t1.Resume ();
// t2.Resume ();
t3.Resume ();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment