Enumerators implementing IDisposable

  • Thread starter Thread starter Andrew Quine
  • Start date Start date
A

Andrew Quine

Hi

Short one: looking for a good example and an explanation of such
enumerators. I know MessageEnumerator and ResourceReader do this, for
example, but what is the implementation of the enumerator doing that
needs a Dispose of its own?

Cheers!

Andrew Quine
 
Andrew,
I can see MessageEnumerator implementing IDisposable if it is implemented in
terms of the underlying Windows API, where the API requires that you "close"
the "windows" handle that you are enumerating over.

For example if MessageEnumerator is implemented in terms of MQCreateCursor,
MQCloseCursor. MQCloseCursor would need to be called by IDisposable...


However I haven't looked at the IL...

Hope this helps
Jay
 
Say you had a database query object, and you could get rows by enumerating
over it. You would want to close it when the enumeration was done.

--
Eric Gunnerson

Visit the C# product team at http://www.csharp.net
Eric's blog is at http://weblogs.asp.net/ericgu/

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top