Home Why no exception occur on a wrong LINQ query in a task (query never ends in a task)
Reply: 0

Why no exception occur on a wrong LINQ query in a task (query never ends in a task)

user662
1#
user662 Published in June 18, 2018, 3:37 am

The code below fails because of Null Exception.

    static void Main(string[] args)
    {
        List<int> ints = null;

        int a = ints.Where(x => x == 10).Single();
    }

But this code never ends and no exception

    static void Main(string[] args)
    {
        Task.Run(() => Method());
    }

    public static async Task Method()
    {
        List<int> ints = null;

        int a = ints.Where(x => x == 10).Single();
    }

Why does nothing happen in second code?
What is going on?
Would you please explain it in a deep detail.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.316409 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO