Chapter 10. Optimizing .NET Data Access

10.0. Introduction

This chapter examines asynchronous processing, caching, paging, batching, and class-specific methods and techniques to improve application performance. Before optimizing any application, profile it to ensure that you have a good understanding of where the real bottlenecks are.

ADO.NET 2.0 introduces the ability to execute queries asynchronously. This lets you execute long-running T-SQL statements and both DataReader and XmlReader queries on a background thread, leaving the user interface responsive or letting you continue with other tasks. Recipe 10.2 shows how. You can execute multiple queries simultaneously, waiting for each or all to finish. Recipe 10.3 shows you how to do this.

A query can run asynchronously on background threads to improve application responsiveness and perceived performance by not blocking processing. This can also be used to give the user an opportunity to cancel a request that is taking too long. Recipes Recipe 10.4 and Recipe 10.5 shows how to use a background thread to run a query. Recipe 10.6 shows how to let the user cancel a query running on a background thread.

Caching data allows data to be retrieved once and saved in order to service subsequent requests for the same data. The load on the database server is reduced, potentially improving application performance. On the downside, cached data becomes less current (and less accurate) over time. The .NET Framework provides classes to allow both client- ...

Get ADO.NET 3.5 Cookbook, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.