Summary
In this chapter, we have come to an understanding of threads and the thread life cycle. We built some sample code that shows how to create threads with and without parameters. We also looked at running threads in the foreground and background.
Next, we looked at pausing and interrupting threads. Then, we moved on to destroying and canceling threads. You no longer use Thread.Abort
in your code. Thread.Abort
has been responsible for applications crashing at runtime. Instead, you use cancellation tokens. Canceling threads also destroys them.
We looked at scheduling threads with and without parameters. In the next chapter, we will be looking at parallel programming.
Finally, we looked at thread synchronization and locking using lock objects and mutexes and learned how to avoid deadlocks and race conditions.
It is now time to answer some questions to see how well you have retained the knowledge in this chapter. Once you have completed the questions, the Further reading...