views:

94

answers:

1

Hi,

BACKGROUND: I have a WindowForms v3.5 application with a StatusStrip set to be used as a TooStripStatusLabel. I'm issues quite a lot of updates to it during a task that is running, however there are noticable periods where it is BLANK. There are no points when I am writing a blank to the status strip label either.

QUESTION: Any ideas why I would be seeing period where the status strip label is blank, when I don't expect it to be?

How I update it:

    private void UpdateStatusStrip(string text)
    {

        toolStripStatusLabel1.Text = text;
        toolStripStatusLabel1.Invalidate();
        this.Update();
    }

PS. Calling Application.DoEvents() after the this.Update() does not seem to help. I actually am calling this via the backgroundworker control, so:

(a) I start up the background worker:

    private void Sync_Button_Click(object sender, EventArgs e)
    {
        backgroundWorker1.RunWorkerAsync();
        DisableUpdateButtons();
    }

(b) the background worker calls updates:

private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
{
  backgroundWorker1.ReportProgress(1, "Example string");
  MainForm.MyC.SyncFiles(sender);
}

(c) The MyC business class uses it too, e.g.

public void SyncFiles(object sender)
{
    BackgroundWorker bgw = (System.ComponentModel.BackgroundWorker) sender;
    bgw.ReportProgress(1, "Starting sync...");
.
.
.
}

(d) This event picks it up:

    private void backgroundWorker1_ProgressChanged(object sender, System.ComponentModel.ProgressChangedEventArgs e)
    {
        UpdateStatusStrip((string)e.UserState);
    }

(e) And again the update status strip

private void UpdateStatusStrip(string text)
{
    toolStripStatusLabel1.Text = text;
    toolStripStatusLabel1.Invalidate();
    this.Update();
}

Does this help?

+1  A: 

The reason is possibly in the caller of this function. If you call it from another thread, use Control.BeginInvoke instead of direct call. If you call it from the main application thread during long processing, try Application.DoEvents after UpdateStatusStrip call.

Alex Farber
thanks - I've added some more clarity around how I'm using it - would the "Control.BeginInvoke" be required? If yes, where would I be putting this in? I did try "Application.DoEvents after UpdateStatusStrip call" however this didn't help
Greg