In what context is b.test1 () called? If this is a console application and the next thing after calling b.test1 () is terminating the program, then the thread created by b.test1 () will probably never be executed until the program terminates.
You need to wait to allow enough time to create a new thread (expensive) and scheduled for execution. “Multithreaded” and “parallel” do not mean instantaneous. They mean a lot of work per unit of time, averaged over most of the work.
To reduce the cost of a background thread operation, consider replacing new Thread() with ThreadPool.QueueUserWorkItem() to use an existing workflow thread. This will save time and memory.
Also, carefully consider whether the work you push into the background thread is really worth the extra overhead. If logging can potentially block file I / O or network I / O, then doing this in the background thread can be dangerous, but there are other methods for performing asynchronous I / O without having to create a new thread.
Also consider the frequency. It would be better to deploy a background thread that will listen on the queue and sleep most of the time, as well as send the main thread's streaming messages to the queue, than to deploy a new thread each time you want to print a few characters of text.
source share