Interrupting will work fine if the worker thread knows when to go to sleep. You may also need to allow another thread to temporarily stop a different thread and then restart it again later. For example, a worker thread could be doing some intense number crunching when along comes another thread that needs to put a large graphic up on the monitor ASAP. (User interface should almost always get priority.) This scenario can be resolved in at least three ways. You could do nothing special and let the multithreading engine slowly display the graphic. You could raise the priority of the graphic display thread (or lower the priority of the worker thread), thus giving the graphic display more cycles. Or you could suspend the worker thread using the Suspend() method:
Visual Basic
Public Sub Suspend() C#
public void Suspend(); C++
public: void Suspend(); Then, you could draw the graphic and resume the worker thread using the Resume() method: Visual Basic
Public Sub Resume() C#
public void Resume(); C++
public: void Resume(); Background and foreground threads
Two types of threads are available. The first is the foreground thread, which runs until it reaches its exit point or is aborted. The second is the background thread, which terminates upon the completion of the last foreground thread. When you create a thread using the Thread class' constructor, you create a foreground thread by default. To change the thread to a background thread, you must change its IsBackground property to true. The IsBackground property can be toggled at any time while the thread is running. Everything in action
Enough theory; now let's see threads in action. The following example (there are three versions, in different languages) is a true mish mash of threads using all of the method discussed above. There really isn't much rhyme or reason to this example, but all three versions generate output similar to Figure A.
| Figure A |
![]() |







