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)

user6733
1#
user6733 Published in September 21, 2018, 8:03 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.

share|improve this question
  • 4
    Because it's internal task exception msdn.microsoft.com/en-us/library/dd537614(v=vs.110).aspx – Igor Semin Feb 14 at 10:52
  • We can't give you a full-fledged course on async programming here. Fortunately we don't have to because there is one: msdn.microsoft.com/en-us/magazine/jj991977.aspx – Gert Arnold Feb 14 at 11:15
  • @GertArnold thanks. I'll take a look. – qazwsx123 Feb 14 at 11:20

1 Answer 1

active oldest votes
up vote 0 down vote
You need to login account before you can post.

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

© 2016 Powered by mzan.com design MATCHINFO