Hi anirudhp,
Check this example. Now please take its reference and correct your code.
C#
private void Form1_Load(object sender, EventArgs e)
{
lblId.ForeColor = Color.Red;
lblCountry.ForeColor = Color.Red;
System.Windows.Forms.Timer timer1 = new System.Windows.Forms.Timer();
if (lblId.ForeColor == Color.Red)
{
timer1.Start();
System.Threading.Thread thread = new System.Threading.Thread(BlinkId);
thread.Start();
}
if (lblName.ForeColor == Color.Red)
{
timer1.Start();
System.Threading.Thread thread = new System.Threading.Thread(BlinkName);
thread.Start();
}
if (lblCity.ForeColor == Color.Red)
{
timer1.Start();
System.Threading.Thread thread = new System.Threading.Thread(BlinkCity);
thread.Start();
}
if (lblCountry.ForeColor == Color.Red)
{
timer1.Start();
System.Threading.Thread thread = new System.Threading.Thread(BlinkCountry);
thread.Start();
}
}
int count = 10;
private void BlinkId(object o)
{
bool go = false;
while (count > 0)
{
while (!go)
{
lblId.BackColor = Color.White;
go = true;
System.Threading.Thread.Sleep(500);
}
while (go)
{
lblId.BackColor = Color.Green;
go = false;
System.Threading.Thread.Sleep(500);
}
}
}
private void BlinkName(object o)
{
bool go = false;
while (count > 0)
{
while (!go)
{
lblName.BackColor = Color.White;
go = true;
System.Threading.Thread.Sleep(500);
}
while (go)
{
lblName.BackColor = Color.Green;
go = false;
System.Threading.Thread.Sleep(500);
}
}
}
private void BlinkCity(object o)
{
bool go = false;
while (count > 0)
{
while (!go)
{
lblCity.BackColor = Color.White;
go = true;
System.Threading.Thread.Sleep(500);
}
while (go)
{
lblCity.BackColor = Color.Green;
go = false;
System.Threading.Thread.Sleep(500);
}
}
}
private void BlinkCountry(object o)
{
bool go = false;
while (count > 0)
{
while (!go)
{
lblCountry.BackColor = Color.White;
go = true;
System.Threading.Thread.Sleep(500);
}
while (go)
{
lblCountry.BackColor = Color.Green;
go = false;
System.Threading.Thread.Sleep(500);
}
}
}
VB.Net
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
lblId.ForeColor = Color.Red
lblCountry.ForeColor = Color.Red
Dim timer1 As System.Windows.Forms.Timer = New System.Windows.Forms.Timer()
If lblId.ForeColor = Color.Red Then
timer1.Start()
Dim thread As System.Threading.Thread = New System.Threading.Thread(AddressOf BlinkId)
thread.Start()
End If
If lblName.ForeColor = Color.Red Then
timer1.Start()
Dim thread As System.Threading.Thread = New System.Threading.Thread(AddressOf BlinkName)
thread.Start()
End If
If lblCity.ForeColor = Color.Red Then
timer1.Start()
Dim thread As System.Threading.Thread = New System.Threading.Thread(AddressOf BlinkCity)
thread.Start()
End If
If lblCountry.ForeColor = Color.Red Then
timer1.Start()
Dim thread As System.Threading.Thread = New System.Threading.Thread(AddressOf BlinkCountry)
thread.Start()
End If
End Sub
Private count As Integer = 10
Private Sub BlinkId(ByVal o As Object)
Dim go As Boolean = False
While count > 0
While Not go
lblId.BackColor = Color.White
go = True
System.Threading.Thread.Sleep(500)
End While
While go
lblId.BackColor = Color.Green
go = False
System.Threading.Thread.Sleep(500)
End While
End While
End Sub
Private Sub BlinkName(ByVal o As Object)
Dim go As Boolean = False
While count > 0
While Not go
lblName.BackColor = Color.White
go = True
System.Threading.Thread.Sleep(500)
End While
While go
lblName.BackColor = Color.Green
go = False
System.Threading.Thread.Sleep(500)
End While
End While
End Sub
Private Sub BlinkCity(ByVal o As Object)
Dim go As Boolean = False
While count > 0
While Not go
lblCity.BackColor = Color.White
go = True
System.Threading.Thread.Sleep(500)
End While
While go
lblCity.BackColor = Color.Green
go = False
System.Threading.Thread.Sleep(500)
End While
End While
End Sub
Private Sub BlinkCountry(ByVal o As Object)
Dim go As Boolean = False
While count > 0
While Not go
lblCountry.BackColor = Color.White
go = True
System.Threading.Thread.Sleep(500)
End While
While go
lblCountry.BackColor = Color.Green
go = False
System.Threading.Thread.Sleep(500)
End While
End While
End Sub
Screenshot