VB.NET progressbar backgroundworker

后端 未结 6 2118
梦如初夏
梦如初夏 2020-11-28 13:49

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 th

6条回答
  •  抹茶落季
    2020-11-28 14:40

    I understand your desire to make the progressbar the background thread, but I am fairly certain that you will not be able to do this. Because you want to update the visual components of your application, the UI needs to be the primary thread. It is easy enough to disable all of the controls on a form, including menu items.

    Let me suggest this process:

    1. Show your form with the progressbar mentioned.

    2. If you show any other forms, disable all child controls that are directly on the form. Depending on the control, you may have to walk through its child controls to disable them.

    3. In the code that performs the database update, update the progressbar's value to what ever value you desire. Upon updating the value, call the progressbar's refresh method. This will force the progressbar to paint correctly.

    4. Once your update completes, hide the progressbar, re-enable all of the controls on all of the forms that you disabled.

    This will give you the appearance of a progressbar that is running in the background thread while still giving your application the blocking of the main thread as desired.

提交回复
热议问题