Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

Timer in C#

using System;
using System.Threading;

public static class Program {

   public static void Main() {
      // Create a Timer object that knows to call our TimerCallback
      // method once every 2000 milliseconds.
      Timer t = new Timer(TimerCallback, null, 0, 2000);
      // Wait for the user to hit <Enter>
      Console.ReadLine();
   }

   private static void TimerCallback(Object o) {
      // Display the date/time when this method got called.
      Console.WriteLine("In TimerCallback: " + DateTime.Now);
      // Force a garbage collection to occur for this demo.
      GC.Collect();
   }
}
Comment

c# timer

public static void Main()
{
    System.Timers.Timer aTimer = new System.Timers.Timer();
    aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
    aTimer.Interval = 5000;
    aTimer.Enabled = true;

    Console.WriteLine("Press 'q' to quit the sample.");
    while(Console.Read() != 'q');
}

 // Specify what you want to happen when the Elapsed event is raised.
 private static void OnTimedEvent(object source, ElapsedEventArgs e)
 {
     Console.WriteLine("Hello World!");
 }
Comment

PREVIOUS NEXT
Code Example
Csharp :: how to encode and decode a string in c# 
Csharp :: c# string to hex 
Csharp :: bootstrap distane between col 
Csharp :: unity change tmp text from script 
Csharp :: blazor oninitializedasync 
Csharp :: perlin noise unity 
Csharp :: unity dictionary check if key exists 
Csharp :: how to get the position of a camera in unity 
Csharp :: c# display float with 2 decimal places 
Csharp :: merge point 
Csharp :: enable fullscreen unity code 
Csharp :: how to change loaded scene in unity 
Csharp :: how to use file watcher in c# 
Csharp :: asp.net get query string parameter 
Csharp :: how to move towards an object unity 
Csharp :: c# how to refresh your binding source 
Csharp :: unity deltatime 
Csharp :: c# find duplicates in list of strings 
Csharp :: convert generic to type c# 
Csharp :: wpf set color in code 
Csharp :: c# list grouping 
Csharp :: mvc 5 dropdownlist 
Csharp :: how to make a global string c# 
Csharp :: how get query from url in laravel 
Csharp :: two variable in one loop c# 
Csharp :: unity c# debug.log 
Csharp :: how to convert int to float in c# 
Csharp :: c# how to sort a list 
Csharp :: OnMousedown unity ui 
Csharp :: get char lowercase in c# 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =