Chapter 4: Threading Design Principles

 < Day Day Up > 



Overview

Most highly scalable systems are highly concurrent in nature, meaning the existence of more than one request for the same object at the same time. However, it is a huge challenge to write code that is both highly concurrent and thread safe, which means that when one or more threads are accessing shared data, there is no possibility that the data could be corrupted or made inconsistent.

If we use multithreading techniques with a formal threading model, we can write highly scalable code that can work in a concurrent fashion. In the previous chapters, we learned when to use threading and all the details about threading, including the threading traps. In this chapter, we'll learn all about the threading models supported by .NET and how to take advantage of these threading models, as well as some models we can impose on top of .NET to help us design our code.

By default all the .NET applications are multithreaded, which was not the case in VB6. In Windows Forms applications, there is a special thread called the UI thread that controls all the user interface-related functions such as keyboard activities and mouse activities. When long-running, time-consuming processes are running on the UI thread, the application will become unresponsive. If you run such tasks on a newly spun thread different from the default UI thread, your application will behave better, and your user interface will respond better. However, if you thought that creating numerous Thread objects is the only way to achieve this, you would be wrong. You can use several techniques in addition to multithreading, including implementing asynchronous programming and using Timer-based functions, as you saw in Chapter 2.



 < Day Day Up > 



C# Threading Handbook
C# Threading Handbook
ISBN: 1861008295
EAN: 2147483647
Year: 2003
Pages: 74

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net