Creating Foreground VS Thread.Join () Thread

If it foreground threadis a thread that prevents the process from terminating until all the foreground threads belonging to the process have been completed, and if the method Joinblocks the calling thread until the thread terminates, then what is the difference between the two methods?

Foreground Thread:

static void Main()
    {
        Thread foregroundThread = 
            new Thread(new ThreadStart(SomeMethod));
        foregroundThread.Name = "ForegroundThread";

        foregroundThread.IsBackground = false;

        foregroundThread.Start();
    } 

Join () method:

static void Main() 
    {
        Thread thread = 
                new Thread(new ThreadStart(SomeMethod));

        thread.Name = "Thread";
        thread.Start();
        thread.Join();
    }

Is there a difference between the two approaches?

+3
source share
2 answers

, //, , , . , , , , . Join , , , .

foreground , .

, , , . , , , , .

, :

static void Main()
{
   Thread backgroundThread = new Thread(new ThreadStart(SomeMethod));
   thread.IsBackground = true;
   backgroundThread.Start();
} 


static void SomeMethod() 
{
   Thread thread = new Thread(new ThreadStart(SomeOtherMethod));
   thread.Name = "ForegroundThread";
   thread.IsBackground = false;
   thread.Start();
}

, , , , .

+2

Fire Forget.i.e. . Join, .

0

All Articles