This doesnt require any actual problem solving. Just wondering about the nature of something.
I noticed that if I trigger this event twice in a row, selecting the same file both times, I don't get any sort of error even though I have never explicitly closed the file. Does the file close automagically when ReadLine reaches the end of the file, or is it simply OK to attempt to open a file that is already open so long as it is opened by the same application?
private void uIDownloadToolStripMenuItem_Click(object sender, EventArgs e)
{
int lineNum = 1;
using (OpenFileDialog dlgOpen = new OpenFileDialog())
try
{
// Default file extension
dlgOpen.DefaultExt = "*.hex";
// SaveFileDialog title
dlgOpen.Title = "Download UI Image";
// Available file extensions
dlgOpen.Filter = "Hex Files (*.hex)|*.hex|All Files (*.*)|*.*";
// Show SaveFileDialog box and save file
if (dlgOpen.ShowDialog() == DialogResult.OK)
{
dlgOpen.OpenFile();
string file = dlgOpen.FileName;
StreamReader reader = new StreamReader(file);
var result = MessageBox.Show("Please confirm the file:" + file, "Confirm", MessageBoxButtons.OKCancel);
if (result == DialogResult.OK)
{
commandConstruct(OP.SETSTATE, DEV.SPI_DEV, "1" , "");
if (ready == true)
{
using (reader)
{
string check;
bool verified = true;
do
{
check = reader.ReadLine();
} while (check != null);
}
}
}
}
}
catch (Exception errorMsg)
{
MessageBox.Show(errorMsg.Message);
}
}