Wrox Programmer Forums
|
BOOK: ASP.NET Website Programming Problem-Design-Solution
This is the forum to discuss the Wrox book ASP.NET Website Programming: Problem - Design - Solution, Visual Basic .NET Edition by Marco Bellinaso, Kevin Hoffman; ISBN: 9780764543869
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET Website Programming Problem-Design-Solution section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 6th, 2004, 06:54 AM
Registered User
 
Join Date: Nov 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default A Question for Englere! ;)

Hi.

In the sample source code, there are many lines of code similiar to this

using (DataSet temp = SomeMethodWhichReturnsDataSet()) {
 return temp;
}

As far as I know, the purpose of this using block is to force Dispose method to be called on temp object when the control leaves the using block. In this way, we can releases any unmanaged resources used by temp object.

My Question is why do we need to use using block at all????





 
Old November 7th, 2004, 09:06 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 917
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Using always calls Dispose, even if an exception is raised. This is just easier than using "try..finally" all over the place.

The only time you really need to call Dispose (whether it's directly called or indirectly called) is when there's unmanged resources involved.

The key unmanaged resource is normally ADO.NET connections. However, in ASP.NET you typically have a pool of connections managed for you automatically, so there's less need to call Dispose for ASP.NET.

Many people consider it "good practice" to call Dispose anytime a class implements it. It's mostly C++ programmers who migrate to C# that have this outlook, but it's probably the "most correct" outlook, anyway.

Eric





Similar Threads
Thread Thread Starter Forum Replies Last Post
Englere. you are the one who should write books groupmatch BOOK: ASP.NET Website Programming Problem-Design-Solution 29 November 18th, 2004 09:52 PM
A question for Englere & buzzterrier swandown BOOK: ASP.NET Website Programming Problem-Design-Solution 3 October 29th, 2004 10:00 AM
Namespace vs. Folder Structure (Help Englere) groupmatch BOOK: ASP.NET Website Programming Problem-Design-Solution 14 September 8th, 2004 08:05 AM
For englere eureka BOOK: ASP.NET Website Programming Problem-Design-Solution 3 August 27th, 2004 07:13 AM
a question to englere. Futuregame BOOK: ASP.NET Website Programming Problem-Design-Solution 5 March 17th, 2004 12:52 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.