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

Support Task.Wait Method #2406

Closed
geoffreymcgill opened this issue Feb 17, 2017 · 5 comments

Comments

Projects
None yet
4 participants
@geoffreymcgill
Copy link
Member

commented Feb 17, 2017

https://msdn.microsoft.com/en-us/library/system.threading.tasks.task.wait(v=vs.110).aspx

Steps To Reproduce

http://deck.net/85271e9aa4b48060ce45751998acb622

using System;
using System.Threading.Tasks;

public class Example
{
    public static void Main()
    {
        Task t = Task.Run(() => 
        {
            Random rnd = new Random();
            long sum = 0;
            int n = 5000000;
            
            for (int ctr = 1; ctr <= n; ctr++) 
            {
                int number = rnd.Next(0, 101);
                sum += number;
            }

            Console.WriteLine("Total:   {0:N0}", sum);
            Console.WriteLine("Mean:    {0:N2}", sum/n);
            Console.WriteLine("N:       {0:N0}", n);   
        });

        TimeSpan ts = TimeSpan.FromMilliseconds(150);
        
        if (! t.Wait(ts))
        {
           Console.WriteLine("The timeout interval elapsed.");
        }
    }
}

// The example displays output similar to the following:
//       Total:   50,015,714
//       Mean:    50.02
//       N:       1,000,000
// Or it displays the following output:
//      The timeout interval elapsed.

See Also

@hardhub

This comment has been minimized.

Copy link

commented Jul 1, 2017

Hopefully it will be implemented soon.

@geoffreymcgill geoffreymcgill added this to the 16.1 milestone Jul 3, 2017

@geoffreymcgill geoffreymcgill modified the milestones: 16.1, 16.2, 16.x Aug 16, 2017

@geoffreymcgill geoffreymcgill removed this from the 16.x milestone May 21, 2018

@geoffreymcgill

This comment has been minimized.

Copy link
Member Author

commented Mar 12, 2019

Another simplified sample that demonstrates using Task.Wait.

https://deck.net/0934f68b949c3109145770a819870481

using System;
using System.Threading.Tasks;
                
public class Program
{
    public static void Main()
    {
        var result = Task.Run(() =>
        {
            Console.WriteLine("Hello world");
        });

        result.ContinueWith(
            (test) =>
            {
                Console.WriteLine("1");
            }).Wait();

        Console.WriteLine("2");
    }
}
@vladsch

This comment has been minimized.

Copy link
Member

commented Mar 19, 2019

The pull request is created. Timeout is not supported still because the overloads with timeout can be used inside expressions (current implementation correctly handles Wait as a statement only).

I will try to implement timeout overloads lately (however, timeout is not possible for all cases in JS, only for real async tasks like ajax requests and etc )

@vladsch

This comment has been minimized.

Copy link
Member

commented Mar 21, 2019

Timeout and cancellation are implemented now

@fabriciomurta

This comment has been minimized.

Copy link
Contributor

commented Mar 21, 2019

This is fully implemented and merged, except with the detail of timeout handling in the original deck here, which has been logged under #3884. 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.