This question already has answers here:
C# time in microseconds
(4 answers)
How can I get the Windows system time with millisecond resolution?
(10 answers)
Closed 5 years ago.
Need to get the Timestamp value from system time with high resolution (microseconds).
I googled and found that we should use StopWatch. But stopwatch is used for difference between of two different time, is it correct?
Related
This question already has answers here:
WPF inactivity and activity
(5 answers)
Shutdown WPF application after n seconds of inactivity
(4 answers)
Closed 26 days ago.
I’m developing a wpf application. I have a requirement, If application is idle (no mouse movement,key pressed etc) for specific seconds then it should redirect to first page . I have tried many solutions but none is working.
Please share the solution so that I could use it
This question already has answers here:
How to Query an NTP Server using C#?
(6 answers)
Closed 3 years ago.
I need to get the same time on all Instances of my program. How do I do that. DateTime.Now is not accurate(is different on different hardware) enough, I need to get the Time down to 100 ms difference-precision.
You don't want it read locally from each computer, as you don't know that each PC's clock is perfectly in sync (and you can see that they aren't).
So you have two options:
Write something on each computer to maintain precise time.
Get a web based time and all of your computers will be reading the same data. Here is an example from SO: How to get DateTime from the internet?
This question already has answers here:
Can you round a .NET TimeSpan object?
(10 answers)
Closed 6 years ago.
Round timespan seconds I also need do same with .Hours and .Minutes
This:
1.53994 second
to:
1 second
This code worked for me.
TimeSpan ts = TimeSpan.FromSeconds(1.54);
Math.Round(ts.TotalSeconds);
This question already has answers here:
Thread.Sleep for less than 1 millisecond
(6 answers)
Closed 8 years ago.
I need to delay some piece of code from processing for some time in Microseconds.
I tried a lots of things such as thread.Sleep(x), but it has only milliseconds resolution.
I am using .NET 2.0 in MS Visual Studio 2013.
System.Diagnostics.Stopwatch
allows you to get very small (few nanosecond) ticks, which you can convert to microseconds using this. Then you can just let an empty while loop for as long as you need.
Edit: and it even is supported by .NET 2.0.
This question already has answers here:
C# String Format for hours and minutes from decimal
(3 answers)
Closed 9 years ago.
If I have a double like 2.75, is there a way in .Net to format it as '2:45'
If it is for example, 2.75555555555, it should round it to the nearest minute.
I would not mind coding this myself, but I am wondering if .Net can. I checked ToString but did not find anything.
Thanks
Use TimeSpan and its ToString formatter:
TimeSpan timespan = TimeSpan.FromHours(2.75);
string output = timespan.ToString("h\\:mm");
For example
TimeSpan.FromHours(2.75555).ToString("h\\:mm")
outputs
2:45