I want to automatically refresh my result in label in Windows Form. This code works, but text in label isn't changed. In my opinion program have to stop their operation to refresh label. I also tried http://msdn.microsoft.com/en-us/library/system.timers.timer.elapsed.aspx and http://msdn.microsoft.com/query/dev12.query?appId=Dev12IDEF1&l=EN-US&k=k(EHInvalidOperation.WinForms.IllegalCrossThreadCall);k(TargetFrameworkMoniker-.NETFramework,Version%3Dv4.5);k(DevLang-csharp)&rd=true, but it doesn't work neither. It says that thread is different and they can not do it. Also MSNDa code doesn't work for me :(.
private void button1_Click(object sender, EventArgs e)
{
while (true)
{
CaluclateTime();
Thread.Sleep(1000);
}
}
private void CaluclateTime()
{
DateTime zeroDateTime = new DateTime(2014, 9, 16, 15, 00, 0);
//zeroDateTime is a future :).
DateTime now = DateTime.Now;
TimeSpan duration = zeroDateTime - now;
label1.Text = String.Format("Time zero is in: {0}", duration.ToString());
}