Multithreaded Updating of StatusBar

D

Derek Hart

I am using a status bar to show progress for a long database update. With
the single threading, the GUI often gets stuck and does not show updating,
especially when the user clicks to another program and tries to come back.
The multithreading stuff is looking somewhat complicated. Can somebody show
me a pre-built function on how to continuously update a status bar while
another process is running. Should I run the database process on a new
thread and keep the status bar on the main thread?

Derek
 
G

Guest

controls belong to the thread they were created on, so unless you create your
progressbar dynamically from a new thread, it belongs to your programs main
thread. so in order to change the progress bar from another thread, you need
to use Me.Invoke(). you shouldnt access other threads object and such. create
a sub on the main thread like so

Private Sub ChangeProgValue(byval val as integer)

Me.progressbar1.Value = val

end sub

then create a delagate

Private Delegate Sub ProgDelegate(byval y as Integer)

then when you want to change the progress value on the other thread do this
in a sub of the second thread

Dim x as new ProgDelegate(AddressOf ChangeProgValue)
Dim obj() as Object = {some value to change progressbar}

Me.Invoke(x, obj)

that should work for ya
 
G

Guest

controls belong to the thread they were created on, so unless you create your
progressbar dynamically from a new thread, it belongs to your programs main
thread. so in order to change the progress bar from another thread, you need
to use Me.Invoke(). you shouldnt access other threads object and such. create
a sub on the main thread like so

Private Sub ChangeProgValue(byval val as integer)

Me.progressbar1.Value = val

end sub

then create a delagate

Private Delegate Sub ProgDelegate(byval y as Integer)

then when you want to change the progress value on the other thread do this
in a sub of the second thread

Dim x as new ProgDelegate(AddressOf ChangeProgValue)
Dim obj() as Object = {some value to change progressbar}

Me.Invoke(x, obj)

that should work for ya
 
C

Cor Ligthert [MVP]

Derek,

I am always currious which process can run aside a DataBase Update with its
chance on all kind of errors, can you explain it? Moreover because that you
said that you had problems realizing your problem with the progressbar. What
is maybe difficult with the Fill but not with the Update and keeps
automaticly the form alive.

Cor
 
C

Cor Ligthert [MVP]

I did not understand your questions Cor. Can you elaborate?What is the deeper reason that you use multithreading.

In other words which processes run assynchonosly side by side.

Cor
 
D

Derek Hart

I have a long database process that runs, and a status bar that updates
showing progress. If the user moves to another application and moves back
to my app, the status bar is in frozen mode and does not update until the
end of the database process.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top