I'm fiddling around with a small problem. In a C#-program, I've a label whose color initially is black. Whilst a MP3-file is played, the label gets a green color and after the end of the music, the color of the label should be black.
Now, the music is played but the label doesn't get updated. I used several code-examples, but none of them is working. I know that is has something to do with events and invocation, but how must I change this code in order to make it work? In Java I use the SwingUtilities.InvokeLater()-method, but as far as I'm aware there's no counterpart to this in C#..
delegate void LabelUpdate();
private void check()
{
new Thread(new ThreadStart(updateLabel)).Start();
playSound();
next(); // Used to set the label-color to black
}
private void updateLabel()
{
if (label1.InvokeRequired)
{
UpdateBox d = new LabelUpdate(updateLabel);
this.Invoke(d);
}
else
{
label1.ForeColor = Color.Green;
}
}
Any help is greatly appreciated!
Try to add
Application.DoEvents();
after color changing. In my opinion it would be best to write something like: