The process cannot access the file
<p>i have a program that i use to write data to an excel file....and at the same time i use an excel file to import data from the first excel file using (import data) tool</p>

<p>this is part of the program code</p>

<pre><code>    private void Log(string pText)
        {
        //textBox1.AppendText(pText + "\r\n"); // does not put cr lf, why?
        this.BeginInvoke(new MethodInvoker(delegate(){


        textBox1.AppendText(pText);
        textBox1.AppendText("\n");}));

        }
    private void LogStatus(string pText)
        {
        textBox1.AppendText(pText + "\t");
        textBox1.AppendText("\n");
        }




{
 StreamWriter theString = new
 StreamWriter(FileName + ".csv", true);
 theString.WriteLine(DateTime.Now +  dataToSave + "\t\n");
 theString.Close();
</code></pre>

<p>my problem is when i start to debuge my program in Visual C# 2008</p>

<p>it will work will and start to write data to the first excel file....then during the debug process</p>

<p>i want to import data from the first excel file to the second one using import data(it's important for me to do that in real time i cant delay the import process)</p>

<p>the debuging process stopped and the visual C# 2008  higlight this line of the code</p>

<hr>

<pre><code> theString.Close();
</code></pre>

<hr>

<p>and a message popup to me said</p>

<p>The process cannot access the file because another process has locked a portion of the file.</p>

<p>any help in overcome this problem plz</p>

<p>and thanks</p>
