I don't know if this is the reason but you should not create a new
StringBuilder
object inside the while loop using the name of an already existing object (I'm not sure if re-using an object name in this way creates a memory leak.). Just use the existing one:
while (oleDbDataReader.Read())
{
fullFile.Clear();
fullFile.Append(rows);
fullFile.Append("\r\n");
streamWriter1.Write(fullFile.ToString());
}
If this is not the error source it should at least improve the performance.
For the same reason you may also change the generation of the
rows
string.
[EDIT]
From the comments it seems that executing this task within a worker thread may solve the problem. When performing such long running tasks within a GUI thread, that will not be able to respond to messages while the task is executed.
Some links about worker threads:
BackgroundWorker Class (System.ComponentModel)[
^]
BackgroundWorker Class Sample for Beginners[
^]
[/EDIT]