Click here to Skip to main content
14,929,864 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi i have a lot of forms,and i want to show current cloak in each form.
how i can define baseClass and define timer object in this class?
(show time in textBox)

1 solution

Because Timers are a scarce system resource, I would handle it by having a Clock class (or UserControl) which held a static Timer instance. Each individual Clock instance would hook an event handler to the static Timer, so the minimum system resources would be used:
public partial class Clock : UseControl
    private static Timer tim = new Timer();
    public static Clock()
        tim.Tick = 1000;   // One second intervals
    public Clock()
        tim.Tick += new EventHandler(tim_Tick);

    void tim_Tick(object sender, EventArgs e)
VJ Reddy 3-Jun-12 8:18am
Nice answer. 5!

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