Stopwatch application in C#
February 29th, 2008 1:51:12 pm pst by Sterling CamdenAs an independent consultant who bills by the hour, I have to keep track of how much time I spend on projects for different clients. When various emergencies arise, that can get pretty confusing to reconstruct at the end of the day. I needed an easy way to monitor my time with just a few mouse clicks. So a few years ago I created the simple stopwatch application that you can download below. One click to start, another to stop. You can enter a description, and previously entered descriptions are remembered in a dropdown. You can run multiple instances to keep track of time for multiple clients. At the end of the day, you’ve got a total for each.
I wrote this as a C# Windows application using Visual Studio 2003. Converting it for VS 2005 introduced a challenge, because accessing a control from another thread (the timer’s) is now considered unsafe and throws an exception. So as you’ll see in the SetText method, I adopted a work-around from the MSDN documentation.
Back when I wrote this application, the code seemed quite concise. Now that I’m older and wiser and have been exposed to Ruby, I can’t get over how verbose it is. I can’t help but think that to do the same thing in JavaScript would be pretty trivial. Maybe I’ll give it a go one day.
UPDATE 11/10/2008: Here’s the JavaScript version.
Posted in .NET, C#, Wildly popular, Windows | 17 Comments » RSS 2.0





[...] some visual indicator of what project is “on” at any given time. I use a little stopwatch application that I created years ago to keep running totals of time spent on each project. When I can see [...]
Please urgently email me the stop watch application.
This sounds like a great application! I’d like to try it. If it works, I’ll buy it if the price is right.
How’s “free” work for you?
OK, I’ve added the executable (release build) to the zip file. You can download it by pressing the “Give me the code” button on the post above.
Sterlng,
I downloaded the code and got told I had to set up a .NET framework. Too much nonbillable time to figure that out.
I was asking for a plug’n'play app. PCMag (or a site like that) offers nifty little programs for about $8 apiece. I think a year’s subscription to all their download utilities is under $30.
Thanks anyway.
Tom
Sorry it was too much trouble for you, Tom. This site is intended to provide coding examples rather than end-user utilities.
This couldn’t have been any easier. It’s a great tool and I’ll be using it alot. Thanks.
Glad you like it, Scott! Let me know if you have any suggestions.
[...] Here’s a Windows desktop version written in C#, if that suits your style better. [...]
Hi Sterling,
I’m in a similar position as you. I work as a consultant for
several different clients in the NC area.
How do you go about getting new clients? I have a few but could use some tips as to how to get more. (I need to stay consistently busy, so I don’t have to go back to the corporate grind)
Any tips you may have would be appreciated.
Thanks,
Carl
Hi Carl,
I’ve been lucky enough to find a niche and work it for years, so now my reputation precedes me for that type of business. I pretty much fell into it by accident, but it isn’t a bad strategy. If you can identify something that will be in demand long-term, then become an expert at it and tout that in on-line forums and your own web page or blog, business will come to you.
I wrote more suggestions over here.
Hi Sterling,
I just read your article about “Tracking and reporting your IT consulting hours” and ended up on your website because I was interested in your timer solutions. I tried both the java and windows version, they’re great!
I especially liked the system tray options of the windows version, first of all that you can see one or more of the instances if the timer is running or stopped and the passed time just by hovering over them with the mouse.
I thought I’d write here for you because you asked for suggestions, and I do have two, that I thought of right away once I launched the programs the very first time (the java or windows):
1. It would be really useful if the entries and the final time result would be logged automatically to a new line in a txt file (; as separator) when you click on the button “stop”, and where the time value would be recorded in decimal, so that it would make accounting a bit easier.
2. Adding a 2nd text window for “memo”
3. and I just thought of some whistles and bells: a text window (with default value) for your hourly rate for each line and the total sum of the spent time multiplied by the hourly rate.
csv file sample:
name,time,rate,total,memo
joe;1.25;75.00;93.75;ms office got corrupted, reinstalled
Regards,
Geza
Thanks for the suggestions, Geza. I’ll look into adding those enhancements in a future version.
Great!
Thanks.
Geza
i want the procedure to run this application in my computer.i downloaded the file ,but dont know how to run the application
Inside the zip file is a file called StopWatch.exe. That’s the file to execute. You must have the right version of the Microsoft .NET Framework installed. Since this was last built with VS 2005, that would be the .NET Framework 2.0, which you can get here: http://www.microsoft.com/download/en/details.aspx?id=19
Or, if you have a version of Visual Studio later than 2005, just rebuild the solution.