Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - drawstring disappears?

Reply
 
Old 03-11-2009   #1 (permalink)
Tom


 
 

drawstring disappears?

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.


My System SpecsSystem Spec
Old 03-11-2009   #2 (permalink)
Tom


 
 

Re: drawstring disappears?


"Tom" <johnthompson1@xxxxxx> wrote in message
news:56D240F6-D7DE-4637-B72A-26975C5C0E44@xxxxxx
Quote:

>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.

My System SpecsSystem Spec
Old 03-11-2009   #3 (permalink)
Andrew Faust


 
 

Re: drawstring disappears?


"Tom" <johnthompson1@xxxxxx> wrote in message
news:ueBbhXloJHA.2124@xxxxxx
Quote:

>
> "Tom" <johnthompson1@xxxxxx> wrote in message
> news:56D240F6-D7DE-4637-B72A-26975C5C0E44@xxxxxx
Quote:

>>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.
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

My System SpecsSystem Spec
Old 03-11-2009   #4 (permalink)
Tom


 
 

Re: drawstring disappears?


"Andrew Faust" <aef123@xxxxxx> wrote in message
news:uSW5POmoJHA.1292@xxxxxx
Quote:

>
> "Tom" <johnthompson1@xxxxxx> wrote in message
> news:ueBbhXloJHA.2124@xxxxxx
Quote:

>>
>> "Tom" <johnthompson1@xxxxxx> wrote in message
>> news:56D240F6-D7DE-4637-B72A-26975C5C0E44@xxxxxx
Quote:

>>>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.
>
> 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.

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Printing. DrawLine/DrawString. C# [WIN] .NET General
DVD disappears (somewhat different) Vista hardware & devices
Alt-Tab disappears too quick Vista General
vpn disappears in Vista Vista General
Sidebar disappears Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46