Threading in .NET

There are essentially two ways to take advantage of multithreading with .NET:

  • Create a new thread manually by using the System.Threading.Thread class.

  • Use a .NET type that has built-in support for asynchronous use. This includes the types used for file I/O, the XML Web service proxy class, and the Delegate type.

This section focuses on the second approach, which provides most of the benefits of custom threading and shields you from many of the risks. Later in the chapter, we'll examine the first approach and custom threading.

Of course, it's also worth noting that many parts of a .NET application gain the benefits of threading completely for free. When you use the .NET printing classes, for example, the PrintDocument.PrintPage event is fired on a separate thread, allowing your application to remain responsive. Similarly, when you are hosting Web pages or XML Web services through ASP.NET, or components through .NET Remoting, the common language runtime (CLR) automatically uses a pool of worker threads to handle the requests of multiple clients simultaneously. These threads run separate instances of the component, which means that your code rarely needs to take this concurrent use into account. Similarly, if you are offloading the work from your applications to a relational database such as Microsoft SQL Server, you'll benefit from a tested, optimized product that uses a pool of worker threads to efficiently handle high request volumes and intensive file access.



Microsoft. NET Distributed Applications(c) Integrating XML Web Services and. NET Remoting
MicrosoftВ® .NET Distributed Applications: Integrating XML Web Services and .NET Remoting (Pro-Developer)
ISBN: 0735619336
EAN: 2147483647
Year: 2005
Pages: 174

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