C # Attaching Threads

I'm trying to get a good understanding of multithreading in C #, and I'm a bit confused about the applicability of the Thread.Join method. Microsoft says that it "blocks the calling thread until the thread terminates." Two questions:

  • In the following example, which thread is actually blocked and the other is running to terminate?

  • Not the fact that one thread is blocked, but the other runs to completion, actually deprives the target of several threads? (Therefore, I assume that you want to join only in certain situations. What could it be?)

static int Main()
    {
      Alpha oAlpha = new Alpha();
      Thread oThread = new Thread(new ThreadStart(oAlpha.Beta));
      oThread.Start();
      oThread.Join();
    }

I should also note that it is entirely possible that I am not doing something right here.

+3
source share
2 answers

Main , oThread .

, , , , sloppily.

, , .

+3
  • , Main().

  • , , , , . , Start() Join(). , .

0

Source: https://habr.com/ru/post/1719851/


All Articles