It seems that in windows 7, there is some animation that takes place when setting a progress bar's value. Setting the value does not seem to wait for the animation to complete. Is there a way to be notified of when the progress bar has finished animating?
I have a sample program. Please see the comments.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Threading;
namespace Testing
{
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
var form = new Form1();
form.Run();
}
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void Run()
{
Thread thread = new Thread
(
delegate()
{
ProgressBarMax = 10;
ProgressValue = 0;
for (int i = 0; i < 10; i++)
{
Thread.Sleep(1000);
ProgressValue++;
}
}
);
EventHandler show = delegate
{
thread.Start();
};
Shown += show;
ShowDialog();
Shown -= show;
}
public int ProgressBarMax
{
set
{
Invoke
(
(MethodInvoker)
delegate
{
progressBar1.Maximum = value;
}
);
}
}
public int ProgressValue
{
get
{
return progressBar1.Value;
}
set
{
Invoke
(
(MethodInvoker)
delegate
{
label1.Text = value.ToString();
progressBar1.Value = value;
// setting the value is not blocking until the
// animation is completed. it seems to queue
// the animation and as a result a sleep of 1 second
// will cause the animation to sync up with the UI
// thread.
// Thread.Sleep(1000); // this works but is an ugly hack
// i need to know if there is a callback to notify me
// when the progress bar has finished animating.
// then i can wait until that callback is handled
// before continuing.
// if not, do i just create my own progress bar?
}
);
}
}
}
}
My google kung foo seems to be dead today. Thanks.