The code is quite long and complex, so I cannot really paste everything. However, the fundamental problem is as follows: I have a GUI running in the main thread and main pro