QUESTION: Could you explain the execution result of this code?

To write parallel code is not a trivial task. There are details to consider and rules to observe.

Could you say the execution result of the following code? Could you explain why?

using System.Threading.Tasks;
using static System.Console;
class Program
{
    static void Main()
    {
        for (var i = 0; i < 10; i++)
        {
            Task.Factory.StartNew(() => WriteLine(i));
        }

        ReadLine();
    }
}

Share your thoughts in the comments. I will explain what is going on in a future post.

Compartilhe este insight:

Elemar Júnior

Sou fundador e CEO da EximiaCo e atuo como tech trusted advisor ajudando diversas empresas a gerar mais resultados através da tecnologia.

Elemar Júnior

Sou fundador e CEO da EximiaCo e atuo como tech trusted advisor ajudando diversas empresas a gerar mais resultados através da tecnologia.

Mais insights para o seu negócio

Veja mais alguns estudos e reflexões que podem gerar alguns insights para o seu negócio:

In the previous post, I shared some good things about our new query language: RQL. Now, I will show you...
Um de meus temas de estudo preferidos no campo de desenvolvimento é design patterns. Isso sempre me levou a refletir...
Parsing large files is a recurring and challenging task. Right? It is too easy to write slow code that consumes...
Implementing a good caching strategy is fundamental to achieve good performance. Besides that, it is not a trivial task. There...
The following works as expected when building in Debug – the execution is done after three seconds. But, for some...
In this post, I’m going to share with you one of the RavenDB 4 features that I like the most:...