-1

I am writing my own simple count-up timer that could run on any Windows machine. I'm going to write it in VS Code using Angular and Node.JS, and TypeScript.

I would like to understand how to determine (programmatically) the number of tics in a single second on any machine. I primarily program in c#, so I thought I would start there.

My first thoughts : allow the computer to count up in whole numbers for one second and use that value somehow to create my timer.

I searched for this info in StackOverflow, but zero hits were returned.

Su Llewellyn
  • 2,660
  • 2
  • 19
  • 33
  • 1
    I'm not sure what you mean by "tic[k]". I thought a tick is the 10,000,000th of a second, so each second has 10,000,000 ticks, no matter what language or machine. – René Vogt Dec 16 '17 at 20:19
  • Ah, I didn't know this. I thought the number of "ticks" varied by machine, because of processor speed. – Su Llewellyn Dec 16 '17 at 20:45
  • So you probably mean something like cpu-cycles per ms... but I don't think you can count them programmatically, and I'm sure that not every cpu-cycle takes the same time. – René Vogt Dec 16 '17 at 20:49
  • Maybe you mean processor clock rate \ frequency? Number like 2 GHz. – Evk Dec 16 '17 at 20:56
  • Is the processor clock rate used in the implementation of timers? – Su Llewellyn Dec 16 '17 at 20:59
  • Not in 2017, I would say. – Tommaso Belluzzo Dec 16 '17 at 21:01
  • @Tommaso - How would a person go about implementing a custom timer, then? – Su Llewellyn Dec 16 '17 at 21:02
  • I found [this article](https://www.embedded.com/electronics-blogs/beginner-s-corner/4024606/Introduction-to-timer-based-measurement) "Introduction to Timer-based Measurement" - I'll start there first. – Su Llewellyn Dec 16 '17 at 21:04
  • Sincerely, building timer logics from scratch can be a very hard task to accomplish and it requires a great knowledge of low level architecture. What are you trying to achieve, exactly? I mean... is it really necessary to reinvent the wheel or you can achieve your task by using a built-in timer class in your programming language (https://msdn.microsoft.com/en-us/library/system.timers.timer(v=vs.110).aspx)? – Tommaso Belluzzo Dec 16 '17 at 21:05
  • I was trying to find a way to implement my own timer in an Angular/TypeScript app without having to use third-party libraries. – Su Llewellyn Dec 16 '17 at 21:07
  • https://siddii.github.io/angular-timer/ or https://stackoverflow.com/questions/12050268/angularjs-make-a-simple-countdown – Tommaso Belluzzo Dec 16 '17 at 21:10
  • But javascript has `setInterval`\`setTimeout` functions, why not just use that? – Evk Dec 16 '17 at 21:24
  • I wasn't writing in Javascript - c#, Typescript. – Su Llewellyn Dec 16 '17 at 22:50
  • I think I found what I was looking for that seems to fit. Since writing my own timer would be too big a deal, I can use Signal-R. [Link to article](http://www.c-sharpcorner.com/article/asp-net-signalr-angular2-and-typescript-real-time-clock/), "ASP.NET, SignalR, Angular 2 And Typescript Real Time Clock" – Su Llewellyn Dec 16 '17 at 22:58
  • Typescript is superset of javascript, so javascript functions like setInterval can be used in typescript. Well, anyway, if you found what you need - good for you (though I have absolutely no idea how signalr is related to what is described in your question). – Evk Dec 16 '17 at 23:06
  • You're right. I found a better solution: Use the Timer in TypeScript.NET! Here is the link to the Timer class in TypeScript.NET. [Click Me](http://electricessence.github.io/TypeScript.NET/documentation/classes/_source_system_timers_timer_.timer.html) – Su Llewellyn Dec 17 '17 at 14:18

1 Answers1

-1

Make use of the Timer in TypeScript.NET. Link

Su Llewellyn
  • 2,660
  • 2
  • 19
  • 33