I'm using TimeSetEvent and its callback function is working but after a few seconds it fails EVEN if the callback function does no work at all:
// Vars
private TimerEventHandler timerRef;
private uint timerId = 0;
//Later, where I use TimeSetEvent
timerRef = new TimerEventHandler(CallbackFunction);
timerId = timeSetEvent(200, 10, timerRef, UIntPtr.Zero, TIME_KILL_SYNCHRONOUS | TIME_PERIODIC);
Even with 200ms delay it's not working properly.
private void CallbackFunction(uint id, uint msg, UIntPtr userCtx, UIntPtr uIntPtr, UIntPtr intPtr)
{
// Even if this is empty, it will fail
}
I either get NullReferenceException(most of the times) or AccessViolationException (occasionally). I suspect both coming from the same problem.
Funny thing, I have exactly the same structure in another class and it works. I copied that class and here... It doesn't. I get this error.
I don't understand why it's not working (and in the other class it does) and how to solve it.
PD: timerId returns an integer different than 0. I don't understand where this null comes frmo, if I comment TimerId = TimeSetEvent
... Code won't fail.