Segna il video come già completato  
Se vuoi, sarebbe utile un giudizio su questo video    
In questo video vedremo il nuovo metodo Restart() della classe StopWatch di Visual Studio 2010 che è una classe che consente di misurare il tempo trascorso in un intervallo di tempo, oppure il tempo totale di più intervalli. Come vedremo nel corso di quest'esempio, nel corso quindi di questo progetto che abbiamo già caricato il metodo Restart() permette di azzerare il contatore del tempo già trascorso e esegue lo Start() che avvia nuovamente il timer, mentre in Visual Studio 2008 dovevamo stoppare il timer e resettare il contatore e poi effettuare la chiamata al metodo Start(). Analizziamo adesso il progetto così ci risulterà chiaro il significato del metodo Restart(). Questo prima di tutto è un progetto console quindi è un progetto da riga di comando. All'inizio viene richiamato il metodo Main, il metodo AttendiInput che è questo metodo qui sotto e che non fa altro che ripulire lo schermo. Quindi fa il Clear Screen della finestra di DOS e mostra una un'intestazione in alto a sinistra che mostra nello stato del timer. Per cui andiamo a verificare lo stato del timer tramite tramite la proprietà IsRunning che ci restituisce true se il timer è in stato avviato, e ci restituisce false se lo stato invece è arrestato. Quindi di seguito andiamo a scrivere una serie di informazioni per l'utente. Queste formazioni rappresentano la lista dei comandi che l'utente può utilizzare. Per cui una "I" maiuscola per l'avvio del Timer, una "O" sempre maiuscola per l'interruzione del timer. Abbiamo poi la riga che permette di ricevere l'input da parte dell'utente. Infatti tramite il metodo ReadLine() in viene memorizzato l'input dell'utente quindi o "I" oppure "O" nella variabile stringa comando. In base al largo comando che viene è imputato dall'utente la nostra tristezza consolle reagisce in modo diverso. Vediamo quali sono i casi che abbiamo previsto: il caso in cui il comando sia la "I" cioè l'avvio del timer: allora verrà scritta video l'operazione che si sta per compiere cioè è appunto l'avvio del timer e se il timer non è già attivato allora viene effettuato lo Start dell'oggetto Timer. L'oggetto Timer che viene definito qua sopra viene dichiarato e definito qua sopra, non è altro che un oggetto della classe StopWatch. Ritornando al nostro suo switch, nel caso in cui il timer sia già avviato allora si verifica un evento anomalo ed ecco che descriviamo a video il messaggio di errore. Alla fine di questo giro viene riportato l'utente alla lista dei comandi. Nel caso si voglia interrompere lo Stopwatch, allora anche in questo caso dopo tutte le verifiche del caso viene stoppato e viene mostrata a video il tempo trascorso. Possiamo provare questa applicazione lanciandola con F5 oppure premendo questo pulsante in Visual Studio 2010. Ecco, questo è risultato abbiamo quindi quest'interfaccia a riga di comando dove la prima riga appunto è rappresentata dalla non dallo stato dello Stopwatch. E queste sono le informazioni che vengono presentate all'utente se le informazioni dei comandi che possono essere utilizzati. Proviamo ad avviare il timer descrivendo i dettagli come si può verificare dallo stato è avviato. Lo sappiamo premendo "O". E dopo il riavvio lo stato è ora arrestato e ci viene ritornato a video il tempo trascorso dallo Start allo Stop. Premiamo di nuovo un tasto per ritornare alla schermata iniziale lo stato è di nuovo arrestato in pratica in questo progetto, per come stato architettato, viene effettuata un'alternanza di chiamate al metodo Start e al metodo Stop. Se tra il metodo Start e il metodo Stop dello StopWatch non viene richiamato anche il metodo Reset di Visual Studio 2010, allora il tempo trascorso che verrà mostrato quando vedere premiamola o quindi quando arrestiamo lo Stopwatch, farà riferimento al tempo trascorso dal primo start dello Stopwatch. Per cui se si avvia il Timer una volta, lo si riavvia e lo si stoppa una seconda volta allora il tempo che verrà mostrato nel secondo stop non è quello che intercorre dall'ultimo start all'ultimo stop ma dal primo starter all'ultimo stop per cui viene conteggiato tutto il tempo di attività dello stopWatch di Visual Studio 2010. Possiamo anche effettuare una prova concreta allora resettiamo tutto il progetto per ripartire esattamente da capo e andiamo a premere il tasto di avvio debug. Allora, qui siamo nella situazione iniziale. Dobbiamo avviare il timer per cui premiamo il tasto "I" vediamo il timer è ora avviato lo stoppiamo premendo "O" e questo è il tempo trascorso: cinque secondi dallo start allo stop del suo stato era stato nuovamente andiamo di nuovo il timer, lasciamo passare qualche secondo e stoppiamolo nuovamente. Abbiamo come il tempo trascorso di 11 secondi che chiaramente come detto prima, è il tempo di attività tra il primo start e il primo stop e il secondo start ed il secondo stop. Per cui il tempo totale di attività del timer. Proviamo adesso ad utilizzare invece del metodo start il metodo restatart vediamo l'effetto pratico sul nostro progetto. Andiamo ad avviare il timer e lo interrompiamo. Il tempo trascorso sono quattro secondi andiamo di nuovo e stoppiamo. Il tempo trascorso questa volta è un secondo. Quindi è evidente che si è resettato il tempo trascorso dall'ultimo stop allo start successivo. Facciamo di nuovo una veloce prova avviamo il timer di Visual Studio 2010 e le interrompiamo: un secondo e 36. Riavviamo. Adesso abbiamo meno di un secondo. Quindi è evidente che i due tempi, i due intervalli di tempo non vengono sommati. Quindi viene effettuato un reset fra una misurazione e l'altra. Otterremo lo stesso risultato del metodo restatart se effettuassimo un reset e successivamente uno start dello stopwatch. Verifichiamo che sia proprio così: salviamo. Interrompiamo dopo tre secondi avviamo di nuovo, interrompiamo per meno di un secondo quindi assolutamente i due tempi non vengono sommati. Sono verificare concernenti interno del metodo Restart aprendo riflettono andando insistendo i nostri sto cuocere e cercando il metodo restata premiamo il e le verifichiamo che effettivamente il metodo restata presenta il tempo trascorso dall'ultima misurazione desideriamo possiamo anche approfondire il metodo valore starter dello sto cuocere a prender browser visitando quest'indirizzo questa è appunto la documentazione della Microsoft del metodo restata e con tanto di esempi in tutti linguaggi di Visual Studio 2010.
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.