Beispiel #1
0
        public static TT.Task ToTask(this T.CancellationToken ct)
        {
            var tcs = new TT.TaskCompletionSource <bool>();

            ct.Register(() => tcs.SetResult(false));
            return(tcs.Task);
        }
Beispiel #2
0
        public static TT.Task ToTpl(this Task t)
        {
            var tcs = new TT.TaskCompletionSource <bool>();

            t.ContinueWith(x =>
            {
                if (x.IsCanceled)
                {
                    tcs.SetCanceled();
                }
                else if (x.IsFaulted)
                {
                    tcs.SetException(x.Exception);
                }
                else
                {
                    tcs.SetResult(false);
                }
            });
            return(tcs.Task);
        }