Why do I have an exception?
Thread hs;
hs = new Thread(()=>Playsound(sound));
while (bstate==-1)
{
t = Int16.Parse(bpm.Text);
t = 60000 / t;
hs.Start();
cajas[compas-1].Fill = new SolidColorBrush(Colors.White);
cajas[0].Fill = new SolidColorBrush(Colors.Red);
await Task.Delay(t);
for (int k = 1; k < compas-1; k++)
{
hs.Start();
cajas[k-1].Fill = new SolidColorBrush(Colors.White);
cajas[k].Fill = new SolidColorBrush(Colors.Black);
await Task.Delay(t);
}
hs.Start();
cajas[compas - 2].Fill = new SolidColorBrush(Colors.White);
cajas[compas - 1].Fill = new SolidColorBrush(Colors.Black);
await Task.Delay(t);
}
Text of the exception:
System.Threading.ThreadStateException: 'Thread running or terminated; it can not be restarted. ' The exception occurs in the second hs.Start ();