2

There is a code:

using (var sw1 = new StreamWriter(filename))
{
    var sw2 = new StreamWriter(sw1.base as FileStream);
    while (...)
       sw2.WriteLine(...); //a lot of lines are written
}

Can it lose some data without explicit flushing of sw2? According to MSDN (as I remember) internal stream should not be disposed directly, that's why I doesn't cover sw2 by using also.

Why do I need sw1? Cause it's just example and I have same situation in my project as a result of its architecture (sw1 is created out of a function with sw2 and should be passed as FileStream due to an interface).

1 Answer 1

0

Obviously, yes, it can. To prevent data losing sw2 should be flushed before writing to sw1 will be continued. Also sw2 should not be used after sw1 disposing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.