int SvcBusThreadPoolTimer_init( SvcBusThreadPoolTimer* _this, SvcBusThreadPool* pool, SvcBusThreadPool_callback callback, void* context, unsigned int millis ) { FILETIME FileDueTime; ULARGE_INTEGER ulDueTime; _this->timer = CreateThreadpoolTimer( &SvcBusThreadPoolTimer_TimerCallback, _this, &pool->pcbe ); if( _this->timer == NULL ) { return SVCBUS_THREADPOOL_ERROR; } _this->context = context; _this->thread_id = 0; _this->callback = callback; /* notice in the following line of code the negative sign in front of millis casted to __int64. It's to make the SetThreadpoolTimer() API to trigger the first timer relative to current datetime of the system. If using a positive value, it will be an absolute time in 100 nanosecond units since January 1, 1601 (UTC) forcing us to obtain the current datetime and do the arithmetics */ ulDueTime.QuadPart = -(__int64)millis * 10 /* 100 nanosecond increments per microsecond */ * 1000 /* microseconds per millisecond */; FileDueTime.dwHighDateTime = ulDueTime.HighPart; FileDueTime.dwLowDateTime = ulDueTime.LowPart; SetThreadpoolTimer( _this->timer, &FileDueTime, millis, 0 ); return SVCBUS_THREADPOOL_OK; }