From: Arne Vajhøj on
On 17-01-2010 11:31, Family Tree Mike wrote:
> On 1/17/2010 9:40 AM, AMP wrote:
>> I have:
>> writer = XmlWriter.Create("mike.xml",settings);
>> // ......Do Some stuff. This works writes an xml file.
>> // Then I try to close it
>> writer.Flush();
>> writer.Close();
>> //But I get an error saying I cant open it, its being used
>> FileStream fs = new FileStream("mike.xml", FileMode.Open);
>> ....More stuff
>>
>> What am I missing?
>
> Try:
>
> using (XmlWriter writer = XmlWriter.Create("mike.xml", settings))
> {
> // do stuff...
> writer.Flush();
> writer.Close();
> }
>
> using (FileStream fs = new FileStream("mike.xml", FileMode.Open))
> {
> }

The important point being that using will ensure that Dispose
actually gets called.

There should not be functional differences between Close and
Close+Dispose.

Arne