The “correct” way of doing this is with background worker threads really. But this will also work without the need of background worker threads.
Declare a variable in the form class.
Private keepLoopAlive As Boolean
Then write your processing loop to be something like:
keepLoopAlive = True
Do While keepLoopAlive
(your code that loops here)
DoEvents
Loop
Then on your Close event do:
keepLoopAlive = False
Me.Close()
This will cause the loop to end first chance it gets, and your form should close.
Please note I’ve written this code from memory and not in an IDE so there may be typos.