Timer in D.API?

Sam Hu samhu.samhu at gmail.com
Tue Mar 3 20:10:07 PST 2009

First of all,this is about D ,not C#.
In C# the program print each letter of a string per 0.3 second one by one using the Timer & delegate:
C# code:
using System; 
using System.Text; 
using System.Timers; 

namespace OneLetterATime 
    class Program 
        static int counter = 0; 
        static string displayString = @"This string will appear one letter at a time."; 
        static void Main(string[] args) 
            Timer myTimer = new Timer(300); 
            myTimer.Elapsed += new ElapsedEventHandler(WriteChar); 

        static void WriteChar(Object sender, ElapsedEventArgs e) 
I would like to implement the same demand using D+Tango:
D code:
module OneLetterATime; 

import tango.io.Stdout; 
import tango.core.Thread; 
//import samsTools.PromptMessage; 

int main(char[][] args) 
  static int counter=0; 
  static char[] displayString=r"This string will appear one letter at a time."; 
  void writeChar() 
    Thread thisThread=Thread.getThis; 
    for(int counter=0;;counter++) 

  Thread thread=new Thread(&writeChar); 

  return 0; 
But I am not sure whether this is the right D way to meet the goal.Also I would like to know how to abort the program in D as the same does in the above C# program that the program aborts when the user press any key(Console.ReadKey();)?Finally I would like to know is there any API in D or Tango that does the same job as Timer in Windows?

Thank so much for your help.


More information about the Digitalmars-d-learn mailing list