0% found this document useful (0 votes)
8 views

complete-reference-vb_net_85

Uploaded by

khalid
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

complete-reference-vb_net_85

Uploaded by

khalid
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Introduction to Threading

Introduction to Threading
User interfaces and forms applications often present an opportunity to engage additional threads to help keep
the application responsive and enrich the user experience. Applications that perform extensive processing and
limit themselves to single threads can cause the UI and access to controls and components to be locked out
while the main application thread waits for the process attached to the end of it to complete. In simple terms,
locking a user out of an application, even intermittently, is akin to putting a gun to your head and squeezing
the trigger.

Lengthy processes, such as long downloads, backing up data, loading data to databases, extensive searching,
sorts, virus checking, and the like, could and should be allocated to new threads. An application will fast lose
the support of its users if every time it needs to perform a hefty service the user has to take a walk around the
block or do something else to kill some time, like looking for King Solomon's mines.

While there are various techniques that can help increase the responsiveness of the application while it
processes the data necessary to get the job done, nothing is as effective as invoking multiple threads,
especially on computers with only one processor. These threads are fondly known as "workers." You give
them a task to perform and then send them off to do the work, while you continue with the other chores.

The .NET Framework's threading model is equipped to take advantage of the small slices of time between
user−driven events to process data in the background. For example, a user can continue developing,
designing, or configuring an application while the thread recalculates the data in the background within the
same application space.

If your user needs to download an extensive document, search and replace some phrases in a document, or
sort a big array, they can still keep working while another thread performs the computations or tasks that
would normally lock the user out of the application.

Your single application domain of a .NET application can use multiple threads where high−priority threads
can manage time−critical tasks and low−priority threads can cater to ad−hoc access required by the user.
Having multiple threads on the back end, in a server application, also allows more clients to connect to the
service simultaneously. And if the system has multiple processors, multiple threads can be executed on the
additional processing stack in true parallel concurrent processing wizardry.

The downside to threading is that it is much more difficult than single threading to design and implement, as
you will see in the following code. Threads process independently of each other and, by and large, the order of
execution of the threads is nondeterministic. The management of the different threads, controlling the lifetime
of the threads, sharing resources between threads, thread cooperation and interoperation, and so on constitute
a complicated and complex process.

Threading is also resource intensive. The more threads you throw at an application, the more OS and platform
resources you consume. You are still limited by available memory and still have to share hard disks, network
connections, ports, the file system, and, of course, the processor. The .NET Framework's thread model also
involves the instantiation and support of AppDomain objects, which also need to be managed.

In the application design arena, you need to manage threads carefully. If you have too many threads running
the opposite of what you were looking to achieve, application response will suffer. Poorly designed and
implemented threading architecture can bring an application to a halt and cause it to crash.

Thread termination and destruction needs also need to be addressed, and you need to manage and monitor the

569

You might also like