Run a Digital Clock on your WinForm

Set the timer and the refresh period. (1 second) timer1.Enabled = true; timer1.Interval = 1000; Then you need to implement what you want the timer to do every 1 second: private void timer1_Tick(object sender, EventArgs e) { DigiClockTextBox.Text = DateTime.Now.TimeOfDay.ToString(); }

How to execute a method periodically from WPF client application using threading or timer [closed]

I would recommend the System.Threading.Tasks namespace using the new async/await keywords. // The `onTick` method will be called periodically unless cancelled. private static async Task RunPeriodicAsync(Action onTick, TimeSpan dueTime, TimeSpan interval, CancellationToken token) { // Initial wait time before we begin the periodic loop. if(dueTime > TimeSpan.Zero) await Task.Delay(dueTime, token); // Repeat this loop until … Read more

How to start an activity after certain time period?

You can use the Handler class postDelayed() method to perform this: Handler mHandler = new Handler(); mHandler.postDelayed(new Runnable() { @Override public void run() { //start your activity here } }, 1000L); Where 1000L is the time in milliseconds after which the code within the Runnable class will be called. Try to use this .

Javasacript Countdown timer in Days, Hours, Minute, Seconds

I finally got back to looking at this and re-wrote the code and this works like a charm. var upgradeTime = 172801; var seconds = upgradeTime; function timer() { var days = Math.floor(seconds/24/60/60); var hoursLeft = Math.floor((seconds) – (days*86400)); var hours = Math.floor(hoursLeft/3600); var minutesLeft = Math.floor((hoursLeft) – (hours*3600)); var minutes = Math.floor(minutesLeft/60); var remainingSeconds … Read more

SignalR – Checking if a user is still connected

Probably the most used solution is to keep a static variable containing users currently connected and overriding OnConnect and OnDisconnect or implementing IDisconnect depending on the version that you use. You would implement something like this: public class MyHub : Hub { private static List<string> users = new List<string>(); public override Task OnConnected() { users.Add(Context.ConnectionId); … Read more

Running a Java Thread in intervals

I find that a ScheduledExecutorService is an excellent way to do this. It is arguably slightly more complex than a Timer, but gives more flexibility in exchange (e.g. you could choose to use a single thread or a thread pool; it takes units other than solely milliseconds). ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); Runnable periodicTask = new … Read more