drawstring disappears?

  • Thread starter Thread starter Tom
  • Start date Start date
T

Tom

I have a progressbar that I'm creating text on. I'm doing so via the
following inside a function:

graphics = progressBar1.CreateGraphics();

progressBar1.Refresh();
graphics.DrawSTring(
theString,
SystemFonts.DefaultFont,
Brushes.Black,
new PointF(progressbar1.Location.X, progressbar1.Location.Y));

I invoke this function from a background worker thread every second. My
doWork function in my background worker thread is basically the following:

while(true)
{
invokeTheFunctionToUpdateTheProgressBarTextInTheMainGUIThread();
Thread.Sleep(1000);
}

My problem is while the progress bar creates the text over it, the text
seems to disappear and reappear every second. I'm guessing it has something
to do with that Thread.Sleep, but does anybody know how I can update my
progress bar text without having the text seem to flicker?

Thanks.
 
Tom said:
I have a progressbar that I'm creating text on. I'm doing so via the
following inside a function:

graphics = progressBar1.CreateGraphics();

progressBar1.Refresh();
graphics.DrawSTring(
theString,
SystemFonts.DefaultFont,
Brushes.Black,
new PointF(progressbar1.Location.X, progressbar1.Location.Y));

I invoke this function from a background worker thread every second. My
doWork function in my background worker thread is basically the following:

while(true)
{
invokeTheFunctionToUpdateTheProgressBarTextInTheMainGUIThread();
Thread.Sleep(1000);
}

My problem is while the progress bar creates the text over it, the text
seems to disappear and reappear every second. I'm guessing it has
something to do with that Thread.Sleep, but does anybody know how I can
update my progress bar text without having the text seem to flicker?

Thanks.

This seems to definately be affected by the background worker thread
sleeping. If I change the sleep time to be 10 seconds (e.g.
Thread.Sleep(10000)), then the text will disappear for 10 seconds, reappear
for a split second, and repeat that process.
 
Tom said:
This seems to definately be affected by the background worker thread
sleeping. If I change the sleep time to be 10 seconds (e.g.
Thread.Sleep(10000)), then the text will disappear for 10 seconds,
reappear for a split second, and repeat that process.

Are you sure you're not calling Sleep on the main UI thread? If your UI is
frozen while it's sleeping then that is what's happening. If your UI is
still responsive then it may be something else. Could you provide the code
for how you start the thread as well as the
invokeTheFunctionToUpdateTheProgressBarTextInTheMainGUIThread() function?

Andrew Faust
 
Andrew Faust said:
Are you sure you're not calling Sleep on the main UI thread? If your UI is
frozen while it's sleeping then that is what's happening. If your UI is
still responsive then it may be something else. Could you provide the code
for how you start the thread as well as the
invokeTheFunctionToUpdateTheProgressBarTextInTheMainGUIThread() function?

Andrew Faust

Hey Andrew,

Thanks for the response, but I was having so much trouble w/ the progress
bar I gave up and now I'm just using a status panel. I deleted all of my
original code, but I'm pretty sure I was just calling runworkerasync right
after initializecomponent, and i'm my dowork method, i would do the
invoking.
 
Back
Top