Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
IDisposable Mysteries
Message
De
15/04/2011 05:26:52
 
 
À
14/04/2011 17:57:29
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
VB 8.0
OS:
Vista
Network:
Windows XP
Database:
Jet/Access Engine
Application:
Desktop
Divers
Thread ID:
01506168
Message ID:
01507443
Vues:
50
>>>Always check whether a .NET or third-party class implements IDisposable() and, if so, call the Dispose() method when you're finished with it. (There are exceptions to this - sometimes a class (e.g. ADO.NET Connection) will expose a Close() method and using this is preferable)
>>
>>Close is preferrable to Dispose? Is that just because you're explicitly closing the connection, or is there another reason? I usually do the close as the last line in my using block. Actually, I haven't used any ADO.NET classes for a looong time.

>
>I wouldn't say "preferrable", I'd say "interchangeable".

Internally Dispose() calls Close() but not vice versa. OTOH since the clean-up occurs in the Close() method I guess they could regarded as interchangeable.
MS also says that both options will return the connection to the pool (if pooling is enabled) - but here I'm a little confused. I've read that Dispose(), unlike Close(), will clear the connection string. If that is true and it is also returned to the pool I don't see how it will ever be re-used since it won't match any subsequent request for a connection.

Maybe what I read about the connection string being cleared was wrong - I haven't verified it ......
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform