When my application starts, and it has just been upgraded, I am doing a local database update (sqlite).
It is like that:
The user starts my app, and then I start the upgrade process.
During this upgrade process I am showing a form that has a continuous progressbar.
This form closes when the upgrade process is done and the user can then start using my application.
But the progressbar won’t animate since the upgrade process is so intensive.
In my old VB6 version I used an ActiveX-Exe that has 1 form and shows a progressbar. This was my “background worker”.
I am not sure if I can use the same approach in VB.NET.
I have only seen examples that then do the work in the background worker, but I have not seen any examples where the progressbar itself was the background worker.
The database upgrade needs to be blocking, the user may NOT use my application before the database upgrade was done. This means that only the progressbar should “out of process”, but not the upgrading.
Thank you very much!
First read this: Use of Application.DoEvents()
So after reading the above answer you will never using DoEvents ever again, and without the DoEvents (and/or Invalidating the ProgressBar so its Paint event will fire) the "progressbar won’t animate since the upgrade process is so intensive"
Hence Cthulhu’s comment – "You can make a dialog with a progressbar, make that dialog modal and execute your db-stuff on a backgroundworker." is one of the best ways forward.
I have translated a C# implementation of this that I use, you should be able to drop it straight in.
This is the ProgressBar Form:
Drag/Drop a BackgroundWorker control onto the form, here are the background worker events:
And here is the calling code for when your application starts and does the upgrading:
A couple of things, you may prevent the user from Cancelling (ie
lblClose_LinkClicked) and put in protective/defensive programming to handle cases where the user kills the process or turns off their PC during the upgrade.And the ProgressBar is actually an animated gif – and this will suit your usage because estimating the time it takes to update a database is very hard to predict: