I don't know if this is the reason but you should not create a new
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:
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
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