开发者

Winforms StatusStrip - why are there periods where it is blank when I'm updating it?

开发者 https://www.devze.com 2022-12-23 16:38 出处:网络
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 no

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 upd开发者_StackOverflow社区ate 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消