Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
This blog shows on how to use a timer control in C#
WhatsApp
Karthikeyan Anbarasan
13y
2.8
k
0
0
25
Blog
This blog shows on how to use a timer control and how to manipulate the control as per our requirement
using System;
using
System
.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace Demo
{
class Program
{
private static void ThreadingTimer()
{
var t1 = new System.Threading.Timer(
TimeAction, null, TimeSpan.FromSeconds(2),
TimeSpan.FromSeconds(3));
Thread.Sleep(15000);
t1.Dispose();
}
static void TimeAction(object o)
{
Console.WriteLine("System.Threading.Timer {0:T}", DateTime.Now);
}
private static void fntimer()
{
var t1 = new System.Timers.Timer(1000);
t1.AutoReset = true;
t1.Elapsed += TimeAction;
t1.Start();
Thread.Sleep(10000);
t1.Stop();
t1.Dispose();
}
static void TimeAction(object sender, System.Timers.ElapsedEventArgs e)
{
Console.WriteLine("System.Timers.Timer {0:T}", e.SignalTime);
}
static void Main(string[] args)
{
fntimer();
}
}
}
Up Next
Show gridview control cell value in tooptip on mouseover
Ebook Download
View all
Printing in C# Made Easy
Read by 22.3k people
Download Now!
Learn
View all
Membership not found