Environment.TickCount returns negative numbers

tarynkelley

Retired Staff
Retired Staff
Trusted Member
Nov 14, 2015
575
178
28
Parts Unknown
Hey,

is there any way or solution to fix this problem except restarting the server?

Because the value of the TickCount property value is a 32-bit signed integer, if the system runs continuously, TickCount will increment from zero to Int32.MaxValue for approximately 24.9 days, then jump to Int32.MinValue, which is a negative number, then increment back to zero during the next 24.9 days. You can work around this issue by calling the Windows GetTickCount function, which resets to zero after approximately 49.7 days, or by calling the GetTickCount64 function.
https://msdn.microsoft.com/en-us/library/system.environment.tickcount(v=vs.110).aspx
 

BogdanWDK

Administrator
Administrator
Jul 31, 2014
109
285
63
29
United Kingdom
I think it is possible to be fixed since you can call windows functions in c# plugins(am i wrong?).
But i recommend to restart your server every 2-3 days , that way you can keep your plugins up-to-date and apply any edits you've made without forcing server with .reload commands.
 

Jakkee

Retired Staff
Retired Staff
Plugin Developer
Jul 28, 2014
1,465
932
113
Australia
To the TickCount problem I do not know of a fix, But a good temporary solution is to do daily restarts (Early morning, 4am?). I wouldn't recommend keeping your server online without restarts for more than 3-4days
 

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,093
4,784
113
At your house.
github.com

tarynkelley

Retired Staff
Retired Staff
Trusted Member
Nov 14, 2015
575
178
28
Parts Unknown
Why not using GetTickCount64()

https://msdn.microsoft.com/en-us/library/windows/desktop/ms724411(v=vs.85).aspx


C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;

namespace ConsoleApplication1
{
    class Program
    {

        [DllImport("kernel32")]
        extern static UInt64 GetTickCount64();

        static void Main(string[] args)

        {
           
            for (int i = 1; i <= 10; i++)
            {
                ulong result = GetTickCount64();
                Console.WriteLine(result);               
                Console.ReadLine();

            }
        }

    }
}
Result:

50701557
50702087
50702742
50703086
50703413
50703725
50704022
50704365
50704802
50710714

DreTax, are you able to implement the GetTickCount64 function into Fougerite?
 

tarynkelley

Retired Staff
Retired Staff
Trusted Member
Nov 14, 2015
575
178
28
Parts Unknown
When the 24 day pass you have to restart the whole server because all plugins using System Tick don't work properly anymore. And then you have to manually flush the DS DB of the Plugins (e.g. DonatorRank, TimeVoter) etc to get it back to work... TLDR I'm too lazy for that :D
 

Jakkee

Retired Staff
Retired Staff
Plugin Developer
Jul 28, 2014
1,465
932
113
Australia
When the 24 day pass you have to restart the whole server because all plugins using System Tick don't work properly anymore. And then you have to manually flush the DS DB of the Plugins (e.g. DonatorRank, TimeVoter) etc to get it back to work... TLDR I'm too lazy for that :D
That would make sense as when trying to debug on local server I don't find anything wrong (Server not up for more than 1hour)