Just a hint for setting system reference correctly if using C# & Visual Studio 2017.
Please check reply in this post for suitable solution.
— Original Post —
It seems System.Timer doesn’t work properly in fivem.
Sample code (just declare Timer)
public Timer missionTimer;
Exception output when loading resource:
[ 2997938] Failed to instantiate instance of script ScriptAClient.ScriptAClient: System.TypeLoadException: Could not load type of field 'ScriptAClient.ScriptA:missionTimer' (2) due to: Could not resolve type with token 0100001a assembly:System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 type:System.Timers.Timer member:<none>
[ 2997985] at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00018] in <f0e9de1592254c6a8c7c298c474f20de>:0
[ 2998031] at System.RuntimeType.CreateInstanceMono (System.Boolean nonPublic) [0x000a8] in <f0e9de1592254c6a8c7c298c474f20de>:0
[ 2998078] at System.RuntimeType.CreateInstanceSlow (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Threading.StackCrawlMark& stackMark) [0x00009] in <f0e9de1592254c6a8c7c298c474f20de>:0
[ 2998125] at System.RuntimeType.CreateInstanceDefaultCtor (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Threading.StackCrawlMark& stackMark) [0x00027] in <f0e9de1592254c6a8c7c298c474f20de>:0
[ 2998172] at System.Activator.CreateInstance (System.Type type, System.Boolean nonPublic) [0x00020] in <f0e9de1592254c6a8c7c298c474f20de>:0
[ 2998219] at System.Activator.CreateInstance (System.Type type) [0x00000] in <f0e9de1592254c6a8c7c298c474f20de>:0
[ 2998266] at CitizenFX.Core.InternalManager.CreateAssemblyInternal (System.String assemblyFile, System.Byte[] assemblyData, System.Byte[] symbolData) [0x000bb] in C:\gl\builds\edf06b9b\0\cfx\fivem\code\client\clrcore\InternalManager.cs:103
Does anyone know how to use timer in c#?
Thanks in advanced.