I have a form with a button and a label. I want to update the label on the form/UI thread with the value in the print time method. I know that you need to pass a delegate (I think this should be the timer call back) but I'm a little stuck. Here's what I have so far,
Code Snippet
using
System;
using
System.Windows.Forms;
namespace
TimerBallBackTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
System.Threading.
TimerCallback tcb = new System.Threading.TimerCallback(PrintTime);
System.Threading.
Timer t = new System.Threading.Timer(
tcb,
"Hello",
1000,
1000);
}
private void PrintTime(object state)
{
if (label1.InvokeRequired)
{
label1.Text =
DateTime.Now.ToLongTimeString();
}
}
}
}