Garbage collection will not be the reason for this. GC can easily collect millions of objects per second, and most likely you don't have that many sitting around.
If you can repeat this while debugging inside Visual Studio, hit Break All
to break execution. Then, use the Threads
tool window (Ctrl+D,T
) to check all running threads, and switch to each one to see where it is waiting. If you GUI is frozen, it may likely be the inside the Main Thread
(GUI thread).
Most likely, you have a deadlock of some sort, and your app is waiting to acquire a lock.