StatusBar Text not updating

D

dumbledad

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

TimRegan

Hi All,

Thanks for the hints Sijin.

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);
}
}

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.
 

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