Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task.Delay with CancellationToken support #2405

Closed
geoffreymcgill opened this issue Feb 17, 2017 · 1 comment

Comments

Projects
None yet
3 participants
@geoffreymcgill
Copy link
Member

commented Feb 17, 2017

Creates a cancellable task that completes after a time delay.

https://msdn.microsoft.com/en-us/library/hh194865(v=vs.110).aspx

Steps To Reproduce

http://deck.net/85271e9aa4b48060ce45751998acb622

using System;
using System.Threading;
using System.Threading.Tasks;

public class Example
{
    public static void Main()
    {
        CancellationTokenSource source = new CancellationTokenSource();

        var t = Task.Run(async delegate
        {
            // Support required for .Delay with Token
            await Task.Delay(1000, source.Token);

            return 42;
        });
        
        source.Cancel();

        try 
        {
            // Support required for .Wait
            t.Wait();
        }
        catch (AggregateException ae) 
        {
            foreach (var e in ae.InnerExceptions)
            {
                Console.WriteLine("{0}: {1}", e.GetType().Name, e.Message);
            }
        }

        Console.Write("Task t Status: {0}", t.Status);

        if (t.Status == TaskStatus.RanToCompletion)
        {
            Console.Write(", Result: {0}", t.Result);
        }

        source.Dispose();
    }
}

Expected Result

TaskCanceledException: A task was canceled.
Task t Status: Canceled

Actual Result

Compiler Exception

See Also

@fabriciomurta

This comment has been minimized.

Copy link
Contributor

commented May 21, 2019

The implementation works fine and will be included next Bridge release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.