线程进度条未添加到表单中

时间:2015-08-18 09:51:35

标签: c# multithreading progress-bar infragistics

尝试创建一个线程,该线程将修改从类生成的窗口。它还将启动超活动指标。但是,当我运行此代码时,它将修改窗口,但不会添加超活动监视器,并且只会有一个白色矩形。

public void refreshNotification()
{
    Thread backgroundThread = new Thread(
        new ThreadStart(() =>
        {
            window.Size = new System.Drawing.Size(330, 100);
            window.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            window.TransparencyKey = System.Drawing.Color.Turquoise;
            window.BackColor = System.Drawing.Color.Gainsboro;
            window.MouseDown += window_MouseDown;
            window.MouseMove += window_MouseMove;
            window.MouseUp += window_MouseUp;
            UltraActivityIndicator Indicator = customiseActivityIndicator();
            window.Controls.Add(Indicator);
            window.Show();
            while (done == false)
            {
                Thread.Sleep(10);
                //do nothing
            }
            Indicator.Stop();
        }
    ));
    backgroundThread.Start();
}

private static UltraActivityIndicator customiseActivityIndicator()
{
    UltraActivityIndicator Indicator = new UltraActivityIndicator();
    Indicator.Start();
    Indicator.Location = new System.Drawing.Point(50, 35);
    Indicator.Size = new System.Drawing.Size(230, 25);
    Indicator.MarqueeAnimationStyle =               Infragistics.Win.UltraActivityIndicator.MarqueeAnimationStyle.BounceBack;
    Indicator.AnimationSpeed = (25);
    Infragistics.Win.Appearance appearance12 = new Infragistics.Win.Appearance();
    appearance12.BackColor = System.Drawing.Color.CornflowerBlue;
    Indicator.MarqueeFillAppearance = appearance12;

    return Indicator;
}

1 个答案:

答案 0 :(得分:0)

您正在单独的Thread创建窗口,并在使用此代码将Thread完全放入无限Sleep之后:

while (done == false)
{
    Thread.Sleep(10);
    //do nothing
}

这正是您的窗口为白色的原因 - 从Windows的角度来看它很忙。

我建议您在用户界面Thread上创建窗口,并使用BeginInvoke来调整大小和指标逻辑。