In this video we will see the new method restart () in class StopWatch Visual Studio 2010 which is a class that allows you to measure elapsed time over a period of time, or the total time of multiple ranges. As we shall see in the course of this example, in the course of this project then we have already loaded the method restart () allows you to reset the elapsed time and run the Start () which starts the timer again, while in Visual Studio 2008 we had to stop the timer and reset the counter and then call the start () method. We analyze now the project so there will be clarification of the meaning of the method restart ().
This first project is a console so it is a project from the command line. At the start method is called Main, which is the method AttendiInput this method below and that does nothing to clear the screen.
Then the Clear Screen DOS window and displays a header at the top left that shows the status timer.
So let's check the status of the timer by using the property IsRunning that returns true if the timer is started, and it returns false if the state was arrested instead. So below we are going to write a series of user information. These formations represent the list of commands that you can use.
So a capital "I" to start the timer, a "O" always capitalized for the timer interrupt. Then we have the line that can receive input from the user. In fact, using the method ReadLine () is stored in the user input and then "I" or "O" in the command string variable. Based off the command that is our sadness is recognized by the user console reacts differently. Let's see what are the cases that we have planned: the case where the command is the "I" that is, start the timer: the video will be written, then the task you are about to do that is just the start of the timer and if the timer is not already enabled, then the object is performed on the Start Timer. The Timer object that is defined here above is declared and defined here above, is nothing but an object of class StopWatch. Returning to our his switch, if the timer has already started, then there is an anomalous event and here we describe the on-screen error message. At the end of this tour is reported the user to the list of commands. If you want to stop the stopwatch, then again after all required inspections is stopped and the video is shown at elapsed time. We can test this application launched by pressing this button or F5 in Visual Studio 2010. So that was then this interface we have a command line where the first line is represented by not just the state of the Stopwatch. And these are the information that is presented to the user if the information of the commands that can be used. Let's start the timer describing the details as you can check the status is started. We know this by pressing "O". And after the restart it was arrested and now we are back to the time elapsed video from Start to Stop.
Press a button again to return to the initial state is arrested again in practice in this project, as was an architect, is made of alternating calls to Start and Stop method. If between the Start method and the method is not called Stop the StopWatch the method Reset the Visual Studio 2010, then the time that will be shown when seeing premiamola or so when we stop the stopwatch, will refer to the time elapsed from the first start of the Stopwatch . So if you start the timer once it is stopped and restarted a second time then the time will be shown in the second stop is the last stop that elapses from the last start but from the first starter to last stop that is counted as long as the activity stopwatch Visual Studio 2010.
We can also make a concrete proof then reset the entire project to start from scratch and just go to press start debugging. So, here we are in the initial situation.
We need to start the timer so that pressing the "I" we see the timer is now started the stubble pressing "O" and this is the time elapsed: five seconds from the start to the stop of his state had been re-let the timer again, let spend a few seconds and stoppiamolo again.
We as the elapsed time of 11 seconds clearly as I said before, it's time to start work between the first and the first stop and start the second and the second stop.
So the total activity time of the timer. Now let's try to use the method instead of the start method restatart see the practical effect on our project.
Let's start the timer and stops it. The elapsed time is four seconds and go again stopped. Time spent this time is one second. So it's obvious that you reset the time elapsed since the last stop at the next start.
We do a quick test again we start the timer interrupt and Visual Studio 2010, a second and 36. Reboot. Now we have less than a second. So it is clear that the two times, the two time periods are not added. So is a reset between measurements and the other. We'll get the same result if the method restatart a reset and then start of a stopwatch. Make sure that's right: we save. We stop after three seconds we start again, unless we stop for a second then absolutely not the two times are added together. They check on the internal method of opening Restart reflect our emphasis going to cook and I'm looking for is pressed the method and verify that indeed the method has remained the time elapsed since the measurement method we wish we can also deepen the value of the starter I cook take browser by visiting this address, this is precisely the method of documentation in the Microsoft ceased and with lots of examples in all languages of Visual Studio 2010.