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. Recipe10.2 shows how. You can execute multiple queries simultaneously, waiting for each or all to finish. Recipe10.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 Recipe10.4 and Recipe10.5 shows how to use a background thread to run a query. Recipe10.6 shows how to let the user cancel a query running on a background thread.
OF LIVE OAK COUNTY by Mary Margaret Dougherty Campbell
Every evening about 5:45, a white pickup turns onto a caliche street on the edge of town in George West, Texas. The pickup creeps down the secluded street, turns to the right toward the fence, then backs into its self-assigned parking spot on the caliche driveway, almost but never quite hitting the small barbecue pit with its back bumper. The driver leisurely opens his door, eases out, and ambles to the bed of the pickup where he lifts one end of his ice chest lid and takes out two beers. He slides each into its own fat, Flying W Caprock Ranch rubber koozie (the only kind of koozie he’ll use), closes the cooler, and walks toward the garage.
Just before reaching the garage, he sets the two beers on the stop-sign table, using the beer cans to anchor his scratch-off tickets.
From there, he opens the garage door and takes out a white plastic chair. Back at the table, he sets the chair in front of the two beers, sits down, and waits—in the same spot every day. As he waits, he pops the top of one of the beers and takes a long sip. He takes his snuff can from his shirt-front pocket and arranges it on the table beside the koozies. Then, he takes out his pocket knife and scratches some of the tickets, which according to his superstition must be done while he’s alone. That done, he sips again, scratches a few more tickets, and waits. (If he scratches them all at once, it’s bad luck.) Each time he hears a vehicle on the paved road, he looks up to see if anyone is turning onto the caliche street. Meanwhile, he watches the birds and other wildlife in the yard and the goats across
Sooner or later, you're bound to encounter some problem you haven't experienced before,
and which the previous section doesn't cover. Although I've seen hundreds of different things
go wrong with Macs over the years, I still run across novel problems all the time. If the
solution to some problem isn't immediately obvious, I go through a series of steps to narrow
down the possible causes and test remedies until I find one that works. That's what I want to
teach you to do here.
First, I ask you to try some easy all-purpose solutions. But at a certain point, you may
need to look further for help. I describe how to get more information and troubleshooting
advice from a number of different sources.
If I get a headache, I generally take a couple of over-the-counter pain relievers. If
the headache goes away, I don't worry about the cause; I just get on with my day. Only if it
doesn't go away, or recurs, or accompanies other symptoms, will I call my doctor. Lots of
Mac problems fall into the same category. You can try any or all of several all-purpose
procedures that tend to zap lots of common irritations. If the problem goes away, there's no
need to waste time tracking down its exact cause, but if the quick fixes don't work or the
problem comes back, you can move on to more detailed troubleshooting (see Ask the Right Questions, two pages ahead).
Preprocessor directives supply
the compiler with additional information about regions of code. The most common preprocessor
directives are the conditional directives, which provide a way to include
or exclude regions of code from compilation. For example:
In this class, the statement in Foo is compiled as
conditionally dependent upon the presence of the DEBUG
symbol. If we remove the DEBUG symbol, the statement is
not compiled. Preprocessor symbols can be defined within a source file (as we have done),
and they can be passed to the compiler with the /define:
symbol command-line option.
With the #if and #elif
directives, you can use the ||, &&, and
! operators to perform or, and, and not operations
on multiple symbols. The following directive instructs the compiler to include the code that
follows if the TESTMODE symbol is defined and the
DEBUG symbol is not defined:
Bear in mind, however, that you're not building an ordinary C# expression, and the
symbols upon which you operate have absolutely no connection to
variablesstatic or otherwise.
The transformational self: gateway to young adulthood
As T. S. Eliot (1943) reminds us, the end is always to be found in the beginning. So I will end with 1) a digest of the main points of my thesis and invite your opinion as to how well I assembled a case to support it, and 2) an offering of a suggested answer to the question I posed in Chapter One, “When does adolescence end?”
A reviewer suggested I find the “red thread” that will link these disparate domains of knowledge into a coherent unity. I do not think the matter is that simple. Rather, a fabric of red threads woven into a conceptual integration of the components of the transformational self might be more realistic. I will begin with a detailed elaboration of my general thesis and conclude with brief comments about the potential usefulness of my formulation.
General thesis (Chapter One)
I now turn to a summary of the main points of my thesis.
With the proliferation of interpersonal and intrapsychic psychological theories vigorously competing for the attention of students and veteran clinicians alike, confusion abounds. The clinician lacks an overarching framework resulting in the very real risk of incoherence.