Understanding Threading and Application Shutdown

In Chapter 2, we state that an application terminates when its main form exits. The precise and more correct statement is that an application terminates when all foreground threads have exited. If an application does not create any threads, the only foreground thread is the main thread, and it terminates when the main form is closed; hence the original statement is true for such applications. This means you must understand what foreground threads are and how to ensure thatthey are terminated before the main form closes.

Background Threads

.NET threads can be foreground or background threads. By default, every thread explicitly created is a foreground thread and every thread from the ThreadPool or ...

Get Microsoft® Mobile Development Handbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.