And, what happened when you tried your code ? Was there an error ? Did it not do something you expected it to ?
You need to study the documentation and example on MSDN: [
^].
Set the Property 'WorkerSupportsCancellation of the BackgroundWorker to true, and check the 'CancellationPending Property inside the loop in your 'DoWork method; if 'CancellationPending is 'true set the e.Cancel EventArgs Property to 'true.
Call 'CancelAsynch to stop the Worker. The example on MSDN demonstrates everything you need to know.
Copying code you find on the web and not actually studying documentation, or searching CodeProject or StackOverFlow for examples, or tips, is a good way to make sure you do not progress in learning how to program.
Think how good you are going to feel as you begin to know you are actually
mastering the power of the .NET and the C# language, how you are going to say to yourself: "well, that hard work was worth it." :)