how do I make a status bar?

G

Guest

hey, I have a status bar, and a timer control, and a statc variable.

every 0.5 seconds, the timer sets the status bar text to the variable.

then I can just change the variable's value whenever I want, which will in
turn display in the status bar. it works great.

my problem is that when I do database calls, or use SMO to get all the
available SQL servers, or other processor intensive stuff, the status bar
locks up till its done.

is there some way to make the status bar change even whe nthe computer is
busy ? it seems really unresponsive otherwise.

I tried making a separate thread in the timer tick event to change the
status, but it ends up erroring out because of multiple threads accessing the
same control.

any advice is appreciated. thanks.
 
N

Nicholas Paldino [.NET/C# MVP]

Rogelio,

You are kind of on the right track, but you have things switched around.
The reason why the status bar freezes up is because you are doing work on
the UI thread which is blocking the UI from being redrawn (as well as your
status bar from receiving notifications to be redrawn when the value is
changed).

Because of this, you will have to do the work (database calls, SMO, etc,
etc) on another thread, and then call the Invoke method on a form/control,
passing a delegate which will execute and update the UI (since you can not
update the UI on a thread other than the thread that created the window).
 

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