Strange progress bar behavior !

H

Heandel

Hello,

I have an extremely simple code working with a progress bar.
The progress bar style is set to "marquee" in the visual studio winforms
designer. Fine.

Now I have a line that changes the progress bar style to continuous :
progressBar1.Style = ProgressBarStyle.Continuous;

Awesomely simple.

But then, the progress bar disappears for some reason.
I've tried refreshing the control and the whole form too, the progress bar
stays hidden.

I'm using Windows 7.

What could cause this strange behavior ?

Thanks in advance,


Heandel
 
P

Peter Duniho

Heandel said:
[...]
But then, the progress bar disappears for some reason.
I've tried refreshing the control and the whole form too, the progress
bar stays hidden.

I'm using Windows 7.

What could cause this strange behavior ?

Any number of things. Without a concise-but-complete code example, it's
impossible to say for sure.

But I would guess the most likely cause is the failure to allow window
messages to be pumped on the thread that owns the progress bar. This
usually happens for one of two reasons:

— You are executing some lengthy processing on the same thread that
owns the progress bar, or
— You have created the progress bar in a thread that doesn't have a
message pump loop (i.e. doesn't call Application.Run())

Pete
 
H

Heandel

Pete,

Thank you for your answer, it helped me find what was wrong. I was in fact
setting the style from a thread that didn't own the progress bar.
Invoking the style change via a delegate solved the problem.

Heandel
 
P

Peter Duniho

Heandel said:
Pete,

Thank you for your answer, it helped me find what was wrong. I was in
fact setting the style from a thread that didn't own the progress bar.
Invoking the style change via a delegate solved the problem.

Right. That falls into the second category of possibilities I
mentioned: the progress bar is created on a thread that doesn't have a
message pump.

More specifically, while you may or may not have created the ProgressBar
class instance in the correct thread, that object instance does not have
the actual control window handle initially.

Any operation on the instance that requires the instance's unmanaged
window handle will wind up creating that window handle if it doesn't
already exist. So further operations on the control must continue to
happen on the correct thread, lest some operation result in the creation
of the window handle in the wrong thread.

In other words, by setting the style in the wrong thread, you
inadvertently created the actual control (that is, the unmanaged window
handle) in the wrong thread, one without a message pump loop.

Pete
 

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