Click here to Skip to main content
15,885,899 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I want to reapeat a code so I used a timer with 500 as interval, but this noticeable is this possible using threading? if yes could anyone help me with this please.
code to be repeated with 500 interval:

C#
if (checkBox2.Checked)
          {
              PointOnTerrainGE pot = ge.GetPointOnTerrainFromScreenCoords(0, 0);
              label1.Text = pot.Altitude.ToString();
              label2.Text = pot.Latitude.ToString();
          }


Thank you all.
Posted

1 solution

Hi,

Write code like below.

C#
Timer timer = new Timer();
public FormWithTimer()
{
   timer.Tick += new EventHandler(Method_Do); //Method_Do will be called
   timer.Interval = (500) * (1); 
   timer.Enabled = true;                       
   timer.Start();            
}

public void Method_Do(object sender, EventArgs e)
{
   if (checkBox2.Checked)
   {
       PointOnTerrainGE pot = ge.GetPointOnTerrainFromScreenCoords(0, 0);
       label1.Text = pot.Altitude.ToString();
       label2.Text = pot.Latitude.ToString();
   }
}


Hope this will help you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900