A thread is one example of an object whose lifetime is not controlled by the garbage collector. Under the hood, this is an object of the operating system. This is live while the thread is working with code. The Thread class is just a wrapper. Another example is a window, it is live until your code or user closes it. Winforms does not require you to contain a reference to the shell of the Form class. And you usually do not do this:
Application.Run(new Form1());
- boiler plate code, you do not keep a link to an instance of the Form1 class anywhere.
You can always recreate a Thread object from an existing thread. You do this with Thread.CurrentThread. And it does not have to be a thread created using the Thread constructor. It can be used inside threadpool thread. Or a thread that was not started by managed code. The main thread of your program would be a good example of this; it was launched by Windows.
However, losing a link to a stream is not good practice. This means that you cannot verify that it is still working. This means that you cannot stop him when you need to stop him. When a user wants to exit your program, for example.
source share