Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27189

How can I make a BackGroundWorker finish/complete when cancelling it?

$
0
0
I have a form which asks the user for input and then turns this into a query, the outcome of which is presented on the screen. To make it quicker, a lot of querying can be beforehand and stored in a cache. I do this using a BackGroundWorker (bw). When the user starts using the app, the background caching should stop. When the user is done it can start again.

This is basically what should happen after the user hits the search button:

Code:

bw.CancelAsync() 'stop caching
DoThings()
bw.RunWorkerAsync() 'restart caching

The problem is that canceling the bw, does halt it's activity, but it doesn't fire the bw.RunWorkerCompleted event. When I want to use it again, it is still active.

How can I make it so that the bw.CancelAsync command actually terminates the BackGroundWorker before DoThings() is called?

Thank you

Viewing all articles
Browse latest Browse all 27189

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>