I had the following code dispersed throughout my program. However I always seem to get the error below. Even though I am using a "using bracket" to dispose of resources I still don't know why this is happening.
Error:
The Process cannot access the file "the file path" because it is being used by another process.
Code:
string folderpath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "AGoogleHistory");
string filecreate;
private void restoreTbasToolStripMenuItem_Click(object sender, EventArgs e)
{
using(StreamReader sr = new StreamReader(filecreate))
{
string s = sr.ReadToEnd();
MessageBox.Show(s, "History", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
try
{
browser.Navigate(new Uri(Address));
using(StreamWriter sw = new StreamWriter(filecreate))
{
sw.WriteLine(Address);
}
}
catch(System.UriFormatException)
{
return;
}
private void clearToolStripMenuItem_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Are You Sure", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
{
File.Delete(filecreate);
}
else
{
}
}