Pause Time in Windows [closed]
Want to improve this question? Add details and clar开发者_JS百科ify the problem by editing this post.
Closed 9 years ago.
Improve this questionI am trying pause time using C#/.NET. I am able to set the time but I would like to set the time to pause.
Does anyone know how to do this?
Command Prompt suggestions would also be helpful.
I'm using Visual Studio 2010 if that matters.
For testing? or real life?
For testing you can mock DateTime.Now (although it is easier to have an IClock
interface). For real usage - I just wouldn't.
Or do you just mean Thread.Sleep
?
I think you are talking about stopping windows time, I imagine this is a not a feature of windows to do this. What are you actually tryting to achieve (other than break windows) there may be alternate solutions.
Well, I'm not sure why you'd want to do this, but, since there is no such thing as a 'PauseTime' function in windows, why don't you just have a service that marks the current time, and then continously sets the system time to that start time. That should achieve the effect of keeping the system time the same.
If you need to find out elapsed time for some debugging work, there's the System.Diagnotics.Stopwatch
class. The page on MSDN has some decent examples on how to use it. I don't know what type of precision you're looking for, so maybe this isn't the class to use if you're looking for high performance timing diagnostics.
Hope this helps!
精彩评论