I have a timer in c# to execute a thread every 10ms:
private void setTimers(IntPtr paramA, List<int> paramB)
{
varTimer= new System.Timers.Timer();
varTimer.Elapsed += delegate { Check(paramA, paramB); };
varTimer.Interval = 10;
varTimer.Start();
}
And the function:
private void Check(IntPtr paramA, List<int> paramB)
{
try
{
acquiredLock= false;
System.Threading.Monitor.TryEnter(syncThreadsC, ref acquiredLock);
if (acquiredLock)
{
// logic
}
else
{
return;
}
}
finally
{
if (acquiredLock)
System.Threading.Monitor.Exit(syncThreadsC);
}
}
I'm asking it to be launched every 10ms and even knowing that it won't be superprecise, I get these numbers if I check with StopWatch when I enter and exit Check
:
[605] [668] [693] [755] [785] [847] [878] [941] [971] [40] [67] [128] [159]
The logic of Check
takes between 1 and 2 ms only. I'm wondering, as I believe there is nothing more precise in c#, if there's anything in c++ to launch a timer every X ms with higher precision. If so, I will do it in an external dll and call it. These numbers are too off for what I need.
Thanks