Hello all
I have a thread that performs some simple I/O within a loop that runs on
a separate thread. I used the using keyword to ensure the writer's disposal:
using (writer)
{
while (myCondition)
{
if (buffer.Count >= this.bufferThreshold)
{
//do some I/O
}
}
}
As requirements have changed, I have to exchange my StreamWriter from
time to time which happens outside of this loop. I can easily close the
current writer and exchange the writer reference:
public void ExchangeFiles()
{
//pause I/O loop
this.Pause();
//close currently used file
writer.Close();
//replace writer reference
writer = new StreamWriter(...);
//continue I/O loop
this.Continue();
}
So far so good, but I don't know whether the using-statement that was
initialized with the original StreamReader reference still works
properly (or I'm messing things up by exchaning the reference). Unit
tests still run nicely but I would like to hear your opinion on this. I
guess I will be save with a try/finally block but if using is ok, I'll
keep the current solution.
Thanks for your advice
Philipp