![]() But, we end up using the code anyway and get through our Senior Project class relatively unscathed.įast forward a few years and now we're professional developers that a company relies on to come up with intelligent and well thought out solutions that won't break down when one of your customers decides to buy a new computer. After all, there is no guarantee that your method will wait exactly one second before executing and now you have issues with things like oversleeping (as if we don't have enough to worry about in that department in our own personal lives) or undersleeping. Now, we're a little better off than we were in high school, but we still have issues with precision. Unfortunately, the snippet - while shorter in length - really isn't that much better. Now, you can take your neat code snippet back to the team and show them how smart you really are. NET, hit "I'm feeling lucky", and copy/paste the first thing on the screen that looks like it just might do the trick. So, you hop on to Google and ask how to delay execution of a function in. You remember coding this up years ago and figure there must be a better way. John being the teacher's pet and an overall slacker will suggest this awesome delay function he learned in high school but, you won't be convinced. ![]() ![]() Something is just running too quickly and we need a way to slow it down a little bit. Right? Let's say we're in our senior design class and we run in to a similar issue with the execution of our application. Obviously, we're so much smarter than we were in high school and learned tons of new programming skills that will land us a sweet gig after graduation. Now, fast forward 4 years to the end of college. Not to mention, if I wanted to convert my sweet new screen-saver-circle-moving-app to run on the iPad (assuming Mono Touch is still supported a year from now, but that's a post for another day), then what? The obvious problem with the above solution (besides that it is lazy and sloppy) is the fact that, while counting a loop from 1 to 1000 on my computer today may take one second, that same loop getting executed a year from now will run in half the time or less. Bad Code, do not use.Īs you can probably imagine, this method slowed the incrementing down just enough to let a classroom full of 30 students witness their very first animated program (Hazzah!) However, even though this was a good-enough solution for a classroom, it's a horrible idea for anything that will eventually end up having more than one user. The idea that my teacher gave at the time was to create a blank for loop that counted to 1000. We needed to come up with a way to slow each iteration of the increment() function so we could actually see what was going on. Obviously, this takes all of the fun out actually being able to see your circle slide across the screen so something needed to be done. This happened because the function that incremented the (x,y) position finished running too quickly to actually notice any movement. The problem every student eventually encountered was, the circle had already moved to the edge of the screen by the time the graphics got loaded and we didn't get to see any animation. I remember in my very first high-school programming class, we were instructed to move a circle from one end of the screen to the other. ![]() Timers allow you to control the execution of your application by being able to define when an action takes place. Timersįirst, we'll start of with an introduction to Timers and how not to implement them. Because, let's face it, you probably aren't going to be re-factoring any time soon. NET to help ensure your application will work as intended for years to come. In this article, I'll attempt to show you how to implement the different Timer and Stopwatch classes in. Unfortunately, most of them center around laziness (the bad kind) and unreliability. Luckily, there are probably a few thousand ways to solve each problem. Two problems that plague new programmers and seasoned professionals alike is the need to delay program execution and get an accurate time how long something takes to execute. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |