function after every 2 second

sachinjain_aspnet used Ask the Experts™
I have a window application in c#, i want if any module like HR, Account, Admin run, it need to run a common function after every 2 second. Can you suggest me how to implement?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Anuradha GoliSystems Development / Support Specialist

Using System.Windows.Forms;

private Timer timer1; 
public void InitTimer()
    timer1 = new Timer();
    timer1.Tick += new EventHandler(timer1_Tick);
    timer1.Interval = 2000; // in milliseconds

private void timer1_Tick(object sender, EventArgs e)

public void isonline()
//       ----------------------

Open in new window


Thats fine , but does i need to implement in every page of my appication ?
High School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009
"Thats fine , but does i need to implement in every page of my appication ?"

That depends on how you've designed your application!

Do you have a "main" form that stays open all the time?...or possibly an MdiParent?

If not, then you'll need somewhere else to house the 2 second loop (or be forced to implement it in every Form; and synchronize it if necessary if more than one form will be open at once).

One possibility is to use an ApplicationContext() and pass that to Application.Run().

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial