nish91
nish91

Reputation: 143

In C# programs, when does a program finish executing?

Is it when all the threads in a process have no more instructions to execute?

Upvotes: 4

Views: 107

Answers (1)

Damien_The_Unbeliever
Damien_The_Unbeliever

Reputation: 239754

  1. When something calls ExitProcess or any morally equivalent functions1, or,

  2. differentiating now between background and foreground threads2, when the last foreground thread stops executing.

Threads stop executing when they return from their initial entry-point method, or, when ExitThread (or moral equivalents) is called on them.


1E.g. Environment.Exit or Environment.FailFast are two common closely equivalent managed versions.

2Foreground and background threads are a managed code concept. Any unmanaged threads started directly through the windows API are the equivalent of foreground threads.

Upvotes: 4

Related Questions