# .net code for a timer?



## Zarxrax (Oct 14, 2010)

I was wondering if anyone has implemented a timer in .net and has some code that they could share?
I've done it, but my implementation seemed to have a lot of lag and it felt like it wasn't very accurate.
I will possibly be writing a PLL training app similar to badmephisto's, but I need to get the timer part figured out before anything else.


----------



## masterofthebass (Oct 14, 2010)

.net isn't a language. Are you using VB, C#, C++, etc?


----------



## Zarxrax (Oct 14, 2010)

C#.
They all use the same framework though, so if its written in any of the supported languages I could probably figure out how to port it to c#.


----------



## masterofthebass (Oct 14, 2010)

just because the microsoft compilers compile it to language the framework can understand does not mean the languages are similar. VB code is going to be quite different from C# code for the same tasks.

anyway, check the System.DateTime class. It has what you need. For a good idea of what to do for a timer, look through the qqTimer code to understand what's going on.


----------



## radmin (Oct 14, 2010)

I think it would be pretty cool to make it in silverlight. Then it could port to several app types including windows phone.

But yea, saying .Net isn't very descriptive. The framework can be used for a variety of application types.


----------



## Zarxrax (Oct 14, 2010)

masterofthebass said:


> anyway, check the System.DateTime class. It has what you need.


 
Wow, that looks way easier than what I had tried to do in the past.


----------



## AvGalen (Oct 14, 2010)

Zarxrax said:


> Wow, that looks way easier than what I had tried to do in the past.


 
wait what? You are making a timer with a framework and you didn't use the provided functionality????
How were you doing it?


----------



## Zarxrax (Oct 14, 2010)

I don't remember exactly, I can check tomorrow though. .Net provides thousands of different functions though, and there are several which are designed for "timing" something. With so many options, its almost impossible to know which ones are most appropriate, sometimes.


----------



## tim (Oct 14, 2010)

AvGalen said:


> wait what? You are making a timer with a framework and you didn't use the provided functionality????
> How were you doing it?


 
Let me guess: A timer event and a counter.


----------



## Johannes91 (Oct 14, 2010)

radmin said:


> I think it would be pretty cool to make it in silverlight. Then it could port to several app types including windows phone.


Silverlight is cool because it's portable? You're funny!


----------



## Zarxrax (Oct 14, 2010)

Actually, it seems I was using a Timer and a Stopwatch.

In any case, that implementation turned out feeling very laggy, so I didn't like it much.

System.DateTime feels much more accurate, and it let me write the timer with MUCH fewer lines of code.
However, I'm now stuck at figuring out how to get it to display the elapsed time while the timer is running.


----------



## tim (Oct 14, 2010)

Zarxrax said:


> However, I'm now stuck at figuring out how to get it to display the elapsed time while the timer is running.


 
http://msdn.microsoft.com/en-us/library/system.timers.timer(VS.71).aspx


----------



## Zarxrax (Oct 14, 2010)

Sweet, its starting to come together nicely now.


----------



## Carson (Oct 14, 2010)

I wrote the WinMo timer in C#. I would be more than happy to share the code with you. It certainly is not "optimized" but it is very functional. The .net compact framework is more restrictive however, so you have many more options available than I did. My only real option was comparing tickcounts.


----------



## Zarxrax (Oct 14, 2010)

Well I've already got my timer working great, but it would still be nice to see, just to see if you did it differently.


----------



## Michiel van der Blonk (Oct 15, 2010)

I made talking timer in VB, then started porting it to .NET some 5 years ago, but I never finished it. If you like I can share some code....


----------



## AvGalen (Oct 15, 2010)

Johannes91 said:


> Silverlight is cool because it's portable? You're funny!


 
Silverlight isn't the best option for portability across operating systems or devices, I agree.

But when the TS is already developing in .NET, Silverlight isn't a bad option for this purpose at all. It CAN run on Windows, Mac and Linux as local apps, browser apps or server apps. and it runs on some other devices (like some phones) as well. Not "write once, run everywhere" but not "1 version of 1 OS on pc only" either.

The framework, development tools and languages that can be used with Silverlight are very good and there are free versions available. Installed base for the runtime is small though. Basically Silverlight is great for developers, not so great on the end-users point (yet?)


----------



## Zarxrax (Oct 16, 2010)

Well, I've got everything finished now except, um... displaying the data.
I was planning to use a listview, but then I found out that you cant really edit the items... so that doesn't work.

I wanna display about 4 different times for each PLL, and not really sure which form controls would be best for this. I'm not really fond of doing 100+ labels.


----------



## tim (Oct 16, 2010)

Zarxrax said:


> I wanna display about 4 different times for each PLL, and not really sure which form controls would be best for this. I'm not really fond of doing 100+ labels.


 
Build your own. That's also a nice exercise.


----------

