I have this code in c # that runs a digital clock:
public partial class Form1 : Form
{
Thread hilo;
public Form1()
{
InitializeComponent();
}
delegate void TiempoDelegado();
public void CambiarTiempo()
{
if (this.InvokeRequired)
{
TiempoDelegado delegado = new TiempoDelegado(CambiarTiempo);
this.Invoke(delegado);
}
else
{
label1.Text = DateTime.Now.Hour.ToString("00") + ":" + DateTime.Now.Minute.ToString("00") + ":" + DateTime.Now.Second.ToString("00");
}
}
private void Tiempo()
{
Thread.Sleep(100);
CambiarTiempo();
Tiempo();
}
private void button1_Click(object sender, EventArgs e)
{
hilo = new Thread(Tiempo);
hilo.Start();
}
}
If you run the clock correctly, but when I want to close the application, I get this error:
How can I solve this?