Hello RaGEZONE.
A few minutes ago a friend asked me to make a running time script for C#.
And now I decide to share it.
At the upper add:
Add a new field/property:PHP Code:using System.Diagnostics;
Add this method:PHP Code:Stopwatch t = new Stopwatch();
In a void, add:PHP Code:static bool IsDivisble(long x, int n)
{
return (x % n) == 0;
}
Between the IsDivisble you can change the title. You can do it on two ways:PHP Code:t = new Stopwatch();
t.Start();
while(t.IsRunning)
{
if (IsDivisble(t.ElapsedMilliseconds, 1000))
{
// READ REST OF TOPIC
}
}
1. Use properties (t.Elasped.Seconds, t.Elasped.Minutes, t.Elasped.Hours, t.Elasped.Days)
Don't use t.Elasped.TotalSeconds as it is NOT only seconds but some other shit.
For example:
If you want not 4 seconds but 04 seconds, you can use t.Elasped.ToString("") with a DateTime format.PHP Code:Console.Title = "Carbon - Runned for " + t.Elasped.Seconds + " second(s), " + t.Elasped.Minutes + " minute(s), " + t.Elasped.Hours + " hour(s), " + t.Elasped.Days + " day(s)";
For the days I suggest to always use t.Elasped.Days.PHP Code:t.Elasped.ToString("ss"); // Gives time in seconds with 2 digits, like 05 seconds
t.Elasped.ToString("mm"); // Gives time in minutes with 2 digits, like 08 minutes
t.Elasped.ToString("hh"); // Gives time in hours with 2 digits, like 04 hours, THIS DOES NOT INCLUDE 24 hour clock
t.Elasped.ToString("HH"); // Gives time in hours with 2 digits, like 06 hours, THIS DOES INCLUDE 24 hour clock
To use it, use for example:
PHP Code:Console.Title = "Carbon - Running for " + t.Elasped.ToString("ss") + " second(s), " + t.Elasped.ToString("mm") + " minute(s) and " + t.Elasped.ToString("HH") + " hour(s)!";



Reply With Quote

