Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / October 2004

Tip: Looking for answers? Try searching our database.

StatusBar Text not updating

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
dumbledad@gmail.com - 12 Oct 2004 21:29 GMT
Hi All,

I have an event handler on the UI thread containing the following lines
of code:

statusBar1.Text = e.msg;
System.Diagnostics.Debug.WriteLine(e.msg);

This is then called repeatedly from the worker thread as it reads lines
from an NNTP server.

The first few thousand calls are written to the VS .Net debug output
pane and the Form's StatusBar, but after a while the StatusBar stops
updating. But if I add in a breakpoint and add a watch on
statusBar1.Text the value is being updated, it's just not reflected in
the UI.

Any idea what's going on and how I should fix it. The StatusBar needs
to be updated frequently as some of the worker tasks take a very long
time so I need the users to be told what is happening.

Thanks,

Tim.

PS Appologies if this post turns up twice, I'm using the Google Groups
2 beta and it <i>seemed</i> to eat my first attempt.
Sijin Joseph - 13 Oct 2004 05:20 GMT
Make sure you are using Control.Invoke() or control.BeginInvoke() to
marshal the call from your worker thread to your UI thread.

Try using Application.DoEvents()

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph

> Hi All,
>
[quoted text clipped - 23 lines]
> PS Appologies if this post turns up twice, I'm using the Google Groups
> 2 beta and it <i>seemed</i> to eat my first attempt.
TimRegan - 13 Oct 2004 14:46 GMT
Hi All,

Thanks for the hints Sijin.

>>> Make sure you are using Control.Invoke() or control.BeginInvoke()
to marshal the call from your worker thread to your UI thread. <<<

I am, here's the full code of the method that updates the status bar
on the UI thread:

public void updateStatusIndicator(object obj, StatusIndicatorEventArgs
e)
{
    if (this.InvokeRequired)
    {
        object [] pList = { this, e };
        this.Invoke(new StatusIndicatorEventHandler(updateStatusIndicator),
pList);
    }
    else
    {
        statusBar1.Text = e.msg;
        System.Diagnostics.Debug.WriteLine(e.msg);
    }
}

>>> Try using Application.DoEvents() <<<

But the UI is on a separate thread which is doing nothing but writing
status messages to the status bar. Where in the above code would it
make sense to add Application.DoEvents()?

Cheers,

Tim.
TimRegan - 13 Oct 2004 20:57 GMT
Hi All,

Sijin Joseph wrote:
>>> Try using Application.DoEvents() <<<

Good call, that fixed it :-)

Thanks,

Tim.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.