Q:

VB 2010 - Stop a loop with a button

I am using VB 2010 , I have a loop that takes something like 5 minutes until it's finish. 
I want to allow the user the option to stop it in the middle or whenever they want. 
There's a button which starts the loop , and after I click it the loop starts running and the button is sort of "stuck". 
I saw something called "background work" in the VB Toolbox, can it be a solution to my problem?  

A:

Start your loop in separate thread and set a flag  which directs the action of the loop .  Keep polling for this flag to see whether user wants to stop the thread inside the loop on thread .  See BackgroundWorker 

