Hi anirudhp,
Check this example. Now please take its reference and correct your code.
I have added Five Label controls in the form and set the BackColor of Color label to red for checking.
Code
C#
private void Form1_Load(object sender, EventArgs e)
{
lblColor.BackColor = Color.Red;
System.Windows.Forms.Timer timer1 = new System.Windows.Forms.Timer();
if (lblColor.BackColor == Color.Red)
{
timer1.Start();
System.Threading.Thread thread = new System.Threading.Thread(Blink);
thread.Start();
}
}
int count = 10;
private void Blink(object o)
{
bool go = false;
while (count > 0)
{
while (!go)
{
lblId.BackColor = Color.Red;
lblName.BackColor = Color.Red;
lblCity.BackColor = Color.Red;
lblCountry.BackColor = Color.Red;
go = true;
System.Threading.Thread.Sleep(1000);
}
while (go)
{
lblId.BackColor = Color.Green;
lblName.BackColor = Color.Green;
lblCity.BackColor = Color.Green;
lblCountry.BackColor = Color.Green;
go = false;
System.Threading.Thread.Sleep(1000);
}
}
}
VB.Net
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
lblColor.BackColor = Color.Red
Dim timer1 As System.Windows.Forms.Timer = New System.Windows.Forms.Timer()
If lblColor.BackColor = Color.Red Then
timer1.Start()
Dim thread As System.Threading.Thread = New System.Threading.Thread(AddressOf Blink)
thread.Start()
End If
End Sub
Private count As Integer = 10
Private Sub Blink(ByVal o As Object)
Dim go As Boolean = False
While count > 0
While Not go
lblId.BackColor = Color.Red
lblName.BackColor = Color.Red
lblCity.BackColor = Color.Red
lblCountry.BackColor = Color.Red
go = True
System.Threading.Thread.Sleep(1000)
End While
While go
lblId.BackColor = Color.Green
lblName.BackColor = Color.Green
lblCity.BackColor = Color.Green
lblCountry.BackColor = Color.Green
go = False
System.Threading.Thread.Sleep(1000)
End While
End While
End Sub
Screenshot