File.ReadLines is implemented with an iterator that opens a stream to the file. We were iterating it several times (calling .Count() and .Element(i) would clone the iterator, which meant constantly reiterating the underlying file stream), and keeping it the iterator in scope kept the file handle open. This caused repeated file saves in VS to be unable to execute (because the file was locked), so VS would pop up a Save As dialog.
Iterating the lines once and then realizing the result into an array allows us to more efficiently compute the results using the string array rather than relying of repetitive file IO and keeping the file handle open.
File.ReadLines is implemented with an iterator that opens a stream to the file. We were iterating it several times (calling
.Count()
and.Element(i)
would clone the iterator, which meant constantly reiterating the underlying file stream), and keeping it the iterator in scope kept the file handle open. This caused repeated file saves in VS to be unable to execute (because the file was locked), so VS would pop up a Save As dialog.Iterating the lines once and then realizing the result into an array allows us to more efficiently compute the results using the string array rather than relying of repetitive file IO and keeping the file handle open.
Resolves #137 Also reported internally as https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1576158