I have created an app in c#, which sends SMS after a defined time gap, for this I am using timer and a label which count number of record(sent messages). now when I click on submit button to start sending sms, it fetches records from DB but when it come to that label portion which shows number of sms it shows an error message System.InvalidOperationExecution Cross-thread operation not valid control 'lblXXX' accessed from a thread other than the thread it was created. My Code is For Button
private void btnSend_Click(object sender, EventArgs e)
{
this.btnSend.Enabled = false;
this.starttimer();
}
For Timer
private void starttimer()
{
System.Timers.Timer timer = new System.Timers.Timer();
timer.Start();
timer.Interval = 3000;
timer.Elapsed += new ElapsedEventHandler(this.time_elapsed);
}
for Lable
while (this.dr.Read())
{
this.lblWeightSMS.Text = Convert.ToString(Convert.ToInt32(this.lblWeightSMS.Text) + 1);