C# 自定义等待窗口

时间:2021-12-24 08:10:38
        private SynchronizationContext syncContext = null;

        public WaitWindow()
{
InitializeComponent();
syncContext = SynchronizationContext.Current;
} private void DisplayProgress()
{
while (true)
{
syncContext.Post(delegate (object target)
{
Label lProgress = (Label)target; if (lProgress.Left + lProgress.Width >= Width)
{
lProgress.Left = ;
}
else
{
lProgress.Left += ;
}
}, lblProgress);
Thread.Sleep();
}
} //waitWnd = new WaitWindow();
//waitWnd.Owner = this;
//waitWnd.Show(); //if (waitWnd != null)
//{
// waitWnd.Close();
//}
private void WaitWindow_Load(object sender, EventArgs e)
{
Thread runProgressThread = new Thread(new ThreadStart(DisplayProgress));
runProgressThread.IsBackground = true;
runProgressThread.Start();
}