Click here to Skip to main content
15,887,371 members
Home / Discussions / C#
   

C#

 
QuestionUsing "using" Pin
#realJSOP6-May-08 4:02
mve#realJSOP6-May-08 4:02 
AnswerRe: Using "using" Pin
Pete O'Hanlon6-May-08 4:17
mvePete O'Hanlon6-May-08 4:17 
GeneralRe: Using "using" Pin
N a v a n e e t h6-May-08 4:25
N a v a n e e t h6-May-08 4:25 
GeneralRe: Using "using" Pin
tgrt6-May-08 4:42
tgrt6-May-08 4:42 
GeneralRe: Using "using" Pin
Colin Angus Mackay6-May-08 4:48
Colin Angus Mackay6-May-08 4:48 
GeneralRe: Using "using" Pin
tgrt6-May-08 5:04
tgrt6-May-08 5:04 
GeneralRe: Using "using" Pin
LongRange.Shooter7-May-08 8:04
LongRange.Shooter7-May-08 8:04 
GeneralRe: Using "using" [modified] Pin
Pete O'Hanlon7-May-08 9:31
mvePete O'Hanlon7-May-08 9:31 
LongRange.Shooter wrote:
The using command, especially when applied to IO resources, is more complex than just calling Dispose.


Nope. It's not. It just calls Dispose. Dispose is responsible for calling Dispose(true), which performs the following code:
protected override void Dispose(bool disposing)
{
    try
    {
        if (((this._handle != null) && !this._handle.IsClosed) && (this._writePos > 0))
        {
            this.FlushWrite(!disposing);
        }
    }
    finally
    {
        if ((this._handle != null) && !this._handle.IsClosed)
        {
            this._handle.Dispose();
        }
        this._canRead = false;
        this._canWrite = false;
        this._canSeek = false;
        base.Dispose(disposing);
    }
}
So, the using block is still about predictably calling Dispose. Don't confuse the effect with the implementation. BTW - there are conditions where the Dispose is not called - in an out of memory or stack overflow, the application bombs straight out (and doesn't hit the Dispose).


Deja View - the feeling that you've seen this post before.

My blog | My articles



modified on Wednesday, May 7, 2008 3:39 PM

GeneralRe: Using "using" Pin
S. Senthil Kumar6-May-08 4:38
S. Senthil Kumar6-May-08 4:38 
GeneralRe: Using "using" Pin
Pete O'Hanlon6-May-08 8:58
mvePete O'Hanlon6-May-08 8:58 
GeneralRe: Using "using" Pin
led mike6-May-08 4:40
led mike6-May-08 4:40 
GeneralRe: Using "using" Pin
#realJSOP7-May-08 0:02
mve#realJSOP7-May-08 0:02 
GeneralRe: Using "using" Pin
Pete O'Hanlon7-May-08 9:36
mvePete O'Hanlon7-May-08 9:36 
GeneralRe: Using "using" Pin
Spacix One7-May-08 11:08
Spacix One7-May-08 11:08 
AnswerRe: Using "using" Pin
N a v a n e e t h6-May-08 4:23
N a v a n e e t h6-May-08 4:23 
AnswerRe: Using "using" Pin
led mike6-May-08 4:31
led mike6-May-08 4:31 
GeneralRe: Using "using" Pin
Roger Alsing6-May-08 7:10
Roger Alsing6-May-08 7:10 
AnswerRe: Using "using" Pin
Guffa6-May-08 4:37
Guffa6-May-08 4:37 
GeneralRe: Using "using" Pin
Roger Alsing6-May-08 7:45
Roger Alsing6-May-08 7:45 
GeneralRe: Using "using" Pin
Guffa6-May-08 9:53
Guffa6-May-08 9:53 
AnswerRe: Using "using" Pin
S. Senthil Kumar6-May-08 4:43
S. Senthil Kumar6-May-08 4:43 
AnswerRe: Using "using" Pin
DavidNohejl6-May-08 4:50
DavidNohejl6-May-08 4:50 
GeneralRe: Using "using" Pin
Pete O'Hanlon6-May-08 9:01
mvePete O'Hanlon6-May-08 9:01 
AnswerRe: Using "using" Pin
PIEBALDconsult6-May-08 5:25
mvePIEBALDconsult6-May-08 5:25 
GeneralRe: Using "using" Pin
Spacix One6-May-08 10:20
Spacix One6-May-08 10:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.