Small is New Big in C#


How to create customer Timer

leave a comment »

C# Verstion:

        private DateTime dt = new DateTime(2010, 06, 30, 00, 00, 01, 00);
        private System.Timers.Timer timer = new System.Timers.Timer();
        private string nowtime;
        public delegate void TimeString(string timestr);

        public void UpdateTimeString(string str)
            label1.Text = str.ToString();

        private void TimeTicking(object sender, System.Timers.ElapsedEventArgs e)
            dt = dt.AddSeconds(1.0);
            nowtime = dt.ToString("HH:mm:ss");
            object[] para = { nowtime };
            this.Invoke(new TimeString(UpdateTimeString), para);

        private void TimeTick()
            timer.Interval = 1000.0;
            timer.Enabled = true;
            timer.Elapsed += new ElapsedEventHandler(TimeTicking);

        private void Form3_Load(object sender, EventArgs e)

VB.NET Version:

Private dt As New DateTime(2010, 6, 30, 0, 0, 1, 0)
Private timer As New System.Timers.Timer()
Private nowtime As String

Public Delegate Sub TimeString(timestr As String)

Public Sub UpdateTimeString(str As String)
label1.Text = str.ToString()
End Sub

Private Sub TimeTicking(sender As Object, e As System.Timers.ElapsedEventArgs)
dt = dt.AddSeconds(1.0)
nowtime = dt.ToString("HH:mm:ss")
Dim para As Object() = {nowtime}
Me.Invoke(New TimeString(AddressOf UpdateTimeString), para)
End Sub

Private Sub TimeTick()
timer.Interval = 1000.0
timer.Enabled = True
AddHandler timer.Elapsed, New ElapsedEventHandler(AddressOf TimeTicking)
End Sub

Private Sub Form3_Load(sender As Object, e As EventArgs)
End Sub


Written by nauhil

June 30, 2010 at 1:47 pm

Posted in Levels Of Details

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: