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 :: c# how to get connection string from app config 
Csharp :: dotnet ef database update connection string 
Csharp :: c# object to dictionary 
Csharp :: custom array initializer in c# 
Csharp :: get folders in directory c# 
Csharp :: c# read file current directory 
Csharp :: int to ascii c# 
Csharp :: get time from datetime c# 
Csharp :: unity 2d player move 
Csharp :: c# get month number 
Csharp :: c# skip following code in loop 
Csharp :: get random color 32 
Csharp :: dictionary c# iterate 
Csharp :: print content of array c# 
Csharp :: decalre an int list mvc 
Csharp :: instantiate unity 
Csharp :: c# minus days from datetime 
Csharp :: Open another form with C# Winforms 
Csharp :: unity detect keyboard not mouse 
Csharp :: scaffold single table to model ef core 
Csharp :: add dependency injection .net core console app 
Csharp :: linq from select 
Csharp :: how to verify the scene unity 
Csharp :: how to use the mouse scroll wheel to move the camera in unity 
Csharp :: list index out of range c# 
Csharp :: set parent of gameobject unity 
Csharp :: asp.net core get root url in view 
Csharp :: c# get list of all class fields 
Csharp :: update squence c# 
Csharp :: c# mongodb update multiple fields 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =