Contains coding, but not narcotic.

Stopwatch application in C#

February 29th, 2008 1:51:12 pm pst by Sterling Camden

As 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

17 Responses to “Stopwatch application in C#”

  1. [...] 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 [...]

  2. Mashea says:

    Please urgently email me the stop watch application.

  3. Tom Durkin says:

    This sounds like a great application! I’d like to try it. If it works, I’ll buy it if the price is right.

  4. 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.

    • Tom Durkin says:

      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

  5. Scott says:

    This couldn’t have been any easier. It’s a great tool and I’ll be using it alot. Thanks.

  6. [...] Here’s a Windows desktop version written in C#, if that suits your style better. [...]

    • Carl says:

      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.

  7. Geza Levai says:

    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

  8. Geza Levai says:

    Great!

    Thanks.

    Geza

  9. sailaja says:

    i want the procedure to run this application in my computer.i downloaded the file ,but dont know how to run the application

Leave a Reply