Marquee Style ProgressBar

J

JB

Hi All,

I have a Windows Form application that shows a "please wait" form
while I query a database for various information.
I display my form using Show, then run my DB query, then Close the
form at the end.

To make it look even nicer I placed a marquee style Progress Bar on my
form.
It works exactly the same way, but the marquee style progress bar
doesn't move at all while I'm running my DB query, which defeats the
purpose. If I don't close my form straight away after my DB query
returns, the progress bar starts moving.

It looks like the DB query thread is taking over the UI threadand
preventing my progress bar to move. However I was under the (naive)
impression that a marquee style progress bar was "thread independent"
and capable of moving as soon as displayed on a form (almost like an
animated Gif). Can somebody tell me if I can get the progress bar to
move while running the DB query without having to run the DB query in
a different thread.

Thanks
JB
 
J

JB

Hi All,

I have a Windows Form application that shows a "please wait" form
while I query a database for various information.
I display my form using Show, then run my DB query, then Close the
form at the end.

To make it look even nicer I placed a marquee style Progress Bar on my
form.
It works exactly the same way, but the marquee style progress bar
doesn't move at all while I'm running my DB query, which defeats the
purpose. If I don't close my form straight away after my DB query
returns, the progress bar starts moving.

It looks like the DB query thread is taking over the UI threadand
preventing my progress bar to move. However I was under the (naive)
impression that a marquee style progress bar was "thread independent"
and capable of moving as soon as displayed on a form (almost like an
animated Gif). Can somebody tell me if I can get the progress bar to
move while running the DB query without having to run the DB query in
a different thread.

Thanks
JB
 
H

Herfried K. Wagner [MVP]

JB said:
I have a Windows Form application that shows a "please wait" form
while I query a database for various information.
I display my form using Show, then run my DB query, then Close the
form at the end.

To make it look even nicer I placed a marquee style Progress Bar on my
form.
It works exactly the same way, but the marquee style progress bar
doesn't move at all while I'm running my DB query, which defeats the
purpose. If I don't close my form straight away after my DB query
returns, the progress bar starts moving.

It looks like the DB query thread is taking over the UI threadand
preventing my progress bar to move. However I was under the (naive)
impression that a marquee style progress bar was "thread independent"
and capable of moving as soon as displayed on a form (almost like an
animated Gif). Can somebody tell me if I can get the progress bar to
move while running the DB query without having to run the DB query in
a different thread.

I suggest to perform the query in the background thread. It's never a good
idea to block the main UI thread because this will prevent user interaction
(closing forms, etc.).
 
J

Jack Jackson

Hi All,

I have a Windows Form application that shows a "please wait" form
while I query a database for various information.
I display my form using Show, then run my DB query, then Close the
form at the end.

To make it look even nicer I placed a marquee style Progress Bar on my
form.
It works exactly the same way, but the marquee style progress bar
doesn't move at all while I'm running my DB query, which defeats the
purpose. If I don't close my form straight away after my DB query
returns, the progress bar starts moving.

It looks like the DB query thread is taking over the UI threadand
preventing my progress bar to move. However I was under the (naive)
impression that a marquee style progress bar was "thread independent"
and capable of moving as soon as displayed on a form (almost like an
animated Gif). Can somebody tell me if I can get the progress bar to
move while running the DB query without having to run the DB query in
a different thread.

Thanks
JB

Unless you explicitly create another thread to do the DB query, it
runs on the UI thread. Likewise the ProgressBar, being a UI control,
runs totally in the UI thread.

To keep the ProgressBar running you need to run the DB query on
another thread. BackgroundWorker works well for this kind of
operation.
 
K

kimiraikkonen

Hi All,

I have a Windows Form application that shows a "please wait" form
while I query a database for various information.
I display my form using Show, then run my DB query, then Close the
form at the end.

To make it look even nicer I placed a marquee style Progress Bar on my
form.
It works exactly the same way, but the marquee style progress bar
doesn't move at all while I'm running my DB query, which defeats the
purpose. If I don't close my form straight away after my DB query
returns, the progress bar starts moving.

It looks like the DB query thread is taking over the UI threadand
preventing my progress bar to move. However I was under the (naive)
impression that a marquee style progress bar was "thread independent"
and capable of moving as soon as displayed on a form (almost like an
animated Gif). Can somebody tell me if I can get the progress bar to
move while running the DB query without having to run the DB query in
a different thread.

Thanks
JB

While querying the DB, probably your UI thread is being blocked,
that's why you need to use BackgroundWorker component to show progress
bar marquee animation during the operation asyncronusly.

Thanks,

Onur Güzel
 
D

davidkurniawan

Try Using BackgroundWorker Component.:

Private Sub LoginBtn_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles LoginBtn.Click
ProgressBar.Style = ProgressBarStyle.Marquee
BackWorker.RunWorkerAsync()
End Sub

Private Sub BackWorker_DoWork(ByVal sender As System.Object, ByVal
e As System.ComponentModel.DoWorkEventArgs) Handles BackWorker.DoWork

doConnect()

End Sub

Private Sub BackWorker_RunWorkerCompleted(ByVal sender As Object,
ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles
BackWorker.RunWorkerCompleted
ProgressBar.Style = ProgressBarStyle.Blocks
If Koneksi.StatusKoneksi = "Terkoneksi" Then Connected()
End Sub
 
J

JB

Hi All,

Thanks for all your suggestions.
I did implement a BackgroundWorder solution and it wasn't that
complicated after all.

JB
 

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