function after every 2 second

sachinjain_aspnet
sachinjain_aspnet used Ask the Experts™
on
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?
Comment
Watch Question

Do more with

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

Commented:
Using System.Windows.Forms;

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

private void timer1_Tick(object sender, EventArgs e)
{
    isonline();
}

public void isonline()
    {
//       ----------------------
    }

Open in new window

Author

Commented:
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
Commented:
"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