Chapter 18: Threading and Synchronization


Highlights

You are making a network call from an application that might take some time. You don’t want to stall the user interface and just let the user wait until the response is returned from the server. The user could do some other actions in the meantime or even cancel the request that was sent to the server. Using threads helps.

There are several reasons for using threading. Not making the user wait is one of the reasons. For all activities that require a wait, for example because of a file, database, or network access, a new thread can be started to fulfill other tasks at the same time. Even if you’ve just processing-intensive tasks to do, threading can help. Multiple threads of a single process can run on different CPUs, or nowadays on different cores of a multiple-core CPU, at the same time.

You must also be aware of some issues running multiple threads. As they can run during the same time, you can easily get into problems if the threads access the same data. You must implement synchronization mechanisms.

This chapter gives you the information you need to know when programming applications with multiple threads, including:

  • An overview of threading

  • Lightweight threading using delegates

  • Thread class

  • Thread pools

  • Threading issues

  • Synchronization techniques

  • COM apartments

  • BackgroundWorker




Professional C# 2005 with .NET 3.0
Professional C# 2005 with .NET 3.0
ISBN: 470124725
EAN: N/A
Year: 2007
Pages: 427

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