int main(int argc, char *argv[]) { HANDLE hThread; DWORD IDThread; LARGE_INTEGER due; ZeroMemory(&due, sizeof(LARGE_INTEGER)); due.QuadPart = -20000000; // 2 - секунды перед стартом таймера hTimer = CreateWaitableTimer(NULL, FALSE, L"MyTimer"); if (hTimer == NULL) { cout << "error CreateWaitableTimer" << endl; return GetLastError(); } if (!SetWaitableTimer(hTimer, &due, 1000, NULL, NULL, 0)) { // дальше повтор с интервалов 1 -сек cout << "error SetWaitableTimer" << endl; return GetLastError(); } hThread = CreateThread(NULL, 0, Thread, NULL, 0, &IDThread); if (hThread == NULL) return GetLastError(); while (!GetAsyncKeyState(VK_ESCAPE)); // чтобы не завершилась приложение пускай ждёт ESC aborts = FALSE; // пускаем сброс цикла в поток для завершения CloseHandle(hThread); CancelWaitableTimer(hTimer); CloseHandle(hTimer); return 0; }
COverlayRenderer::COverlayRenderer(CLibBlurayWrapper* pLib) : m_pLib(pLib), m_pD3DDevice(NULL) { m_pPlanes[BD_OVERLAY_PG] = NULL; m_pPlanes[BD_OVERLAY_IG] = NULL; m_pPlanesBackbuffer[BD_OVERLAY_PG] = NULL; m_pPlanesBackbuffer[BD_OVERLAY_IG] = NULL; m_pARGBTextures[BD_OVERLAY_PG] = NULL; m_pARGBTextures[BD_OVERLAY_IG] = NULL; m_overlayType[BD_OVERLAY_PG] = NONE; m_overlayType[BD_OVERLAY_IG] = NONE; ZeroMemory((void*)&m_ARGBBuffer, sizeof(BD_ARGB_BUFFER_EX)); m_hStopThreadEvent = CreateEvent(0, TRUE, FALSE, 0); m_hNewOverlayAvailable = CreateEvent(0, TRUE, FALSE, 0); m_hThread = CreateThread(0, 0, COverlayRenderer::ScheduleThreadEntryPoint, (LPVOID)this, 0, NULL); m_hOverlayTimerIG = CreateWaitableTimer(NULL, false, NULL); m_hOverlayTimerPG = CreateWaitableTimer(NULL, false, NULL); }
/** * @brief Simple representation of the rt library nanosleep function. */ int ros_nanosleep(const uint32_t &sec, const uint32_t &nsec) { #if defined(WIN32) HANDLE timer = NULL; LARGE_INTEGER sleepTime; sleepTime.QuadPart = - static_cast<int64_t>(sec)*10000000LL - static_cast<int64_t>(nsec) / 100LL; timer = CreateWaitableTimer(NULL, TRUE, NULL); if (timer == NULL) { return -1; } if (!SetWaitableTimer (timer, &sleepTime, 0, NULL, NULL, 0)) { return -1; } if (WaitForSingleObject (timer, INFINITE) != WAIT_OBJECT_0) { return -1; } return 0; #else timespec req = { sec, nsec }; return nanosleep(&req, NULL); #endif }
/* * Custom code called right after loading the plugin. Returns 0 on success, 1 on failure. * If the function returns 1 on failure, the plugin will be unloaded again. */ int ts3plugin_init() { // Create the command mutex hMutex = CreateMutex(NULL, FALSE, NULL); // Create the PTT delay timer hPttDelayTimer = CreateWaitableTimer(NULL, FALSE, NULL); // Find and open the settings database char db[MAX_PATH]; ts3Functions.getConfigPath(db, MAX_PATH); _strcat(db, MAX_PATH, "settings.db"); ts3Settings.OpenDatabase(db); // Find the error sound and info icon SetErrorSound(); SetInfoIcon(); // Start the plugin threads pluginRunning = true; hMailslotThread = CreateThread(NULL, (SIZE_T)NULL, MailslotThread, 0, 0, NULL); if(hMailslotThread==NULL) { ts3Functions.logMessage("Failed to start threads, unloading plugin", LogLevel_ERROR, "NiftyKb Plugin", 0); return 1; } /* Initialize return codes array for requestClientMove */ memset(requestClientMoveReturnCodes, 0, REQUESTCLIENTMOVERETURNCODES_SLOTS * RETURNCODE_BUFSIZE); return 0; /* 0 = success, 1 = failure */ }
HANDLE timer_start(int usec) { timeBeginPeriod(1); hTimer = CreateWaitableTimer(NULL, FALSE, NULL); if(hTimer) { LARGE_INTEGER li = { .QuadPart = -(usec*10) }; if(!SetWaitableTimer(hTimer, &li, usec / 1000, NULL, NULL, FALSE)) { fprintf(stderr, "SetWaitableTimer failed.\n"); hTimer = NULL; } } else { fprintf(stderr, "CreateWaitableTimer failed.\n"); } if(!hTimer) { timeEndPeriod(0); } return hTimer; }
void usleep(DWORD waitTime) { if (waitTime >= 1000) { // Don't do long busy-waits. // However much it seems like the QPC code would be more accurate, // you can and probably will lose your time slice at any point during the wait, // so we might as well voluntarily give up the CPU with a WaitForSingleObject. HANDLE timer; LARGE_INTEGER dueTime; dueTime.QuadPart = -10 * (LONGLONG)waitTime; timer = CreateWaitableTimer(NULL, TRUE, NULL); SetWaitableTimer(timer, &dueTime, 0, NULL, NULL, 0); WaitForSingleObject(timer, INFINITE); CloseHandle(timer); return; } LARGE_INTEGER perf_cnt, start, now; QueryPerformanceFrequency(&perf_cnt); QueryPerformanceCounter(&start); do { QueryPerformanceCounter((LARGE_INTEGER*) &now); } while ((now.QuadPart - start.QuadPart) / (float)perf_cnt.QuadPart * 1000 * 1000 < waitTime); }
void usleep(__int64 waitTime) { if (waitTime > 0) { if (waitTime > 100) { // use a waitable timer for larger intervals > 0.1ms HANDLE timer; LARGE_INTEGER ft; ft.QuadPart = -(10*waitTime); // Convert to 100 nanosecond interval, negative value indicates relative time timer = CreateWaitableTimer(NULL, TRUE, NULL); SetWaitableTimer(timer, &ft, 0, NULL, NULL, 0); WaitForSingleObject(timer, INFINITE); CloseHandle(timer); } else { // use a polling loop for short intervals <= 100ms LARGE_INTEGER perfCnt, start, now; __int64 elapsed; QueryPerformanceFrequency(&perfCnt); QueryPerformanceCounter(&start); do { QueryPerformanceCounter((LARGE_INTEGER*) &now); elapsed = (__int64)((now.QuadPart - start.QuadPart) / (float)perfCnt.QuadPart * 1000 * 1000); } while ( elapsed < waitTime ); } } }
void Delay::waitNsec(uint64_t nsec) { // POSIX. #if defined(DUNE_SYS_HAS_CLOCK_NANOSLEEP) || defined(DUNE_SYS_HAS_NANOSLEEP) timespec ts; ts.tv_sec = nsec / c_nsec_per_sec; ts.tv_nsec = nsec - (ts.tv_sec * c_nsec_per_sec); # if defined(DUNE_SYS_HAS_CLOCK_NANOSLEEP) clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, 0); # else nanosleep(&ts, 0); # endif // Microsoft Windows. #elif defined(DUNE_SYS_HAS_CREATE_WAITABLE_TIMER) HANDLE t = CreateWaitableTimer(0, TRUE, 0); LARGE_INTEGER dl; dl.QuadPart = (uint64_t)nsec / 100; // Negative value means relative time. dl.QuadPart *= -1; SetWaitableTimer(t, &dl, 0, 0, 0, 0); WaitForSingleObject(t, INFINITE); CloseHandle(t); // Unsupported system. #else # error Delay::waitNsec() is not yet implemented in this system #endif }
//设置好相关参数(上传文件的FTP信息,上传文件的时间设置)之后,开始执行设置的定时任务 BOOL FtpConnecter::startUploadTask() { SECURITY_ATTRIBUTES sa; sa.nLength = sizeof(SECURITY_ATTRIBUTES); sa.bInheritHandle = FALSE; sa.lpSecurityDescriptor = NULL; DWORD id; //设置FTP信息 m_FtpInfo._hWaitableTimer = CreateWaitableTimer(&sa, FALSE, NULL); if (m_FtpInfo._hWaitableTimer == NULL) return FALSE; m_FtpInfo._strFolderPath = getRemoteFolderPath(); m_hWorkThread = CreateThread(&sa, 0, UploadeFile, (LPVOID)&m_FtpInfo, 0, &id); if (m_hWorkThread == NULL) { CString strErr = GlobalFunc::formatErrorCode(GetLastError()); strErr = _T("启动上传任务失败,上传文件线程未启动") + strErr; pushTrackInfo(strErr); return FALSE; } SetWaitableTimer(m_FtpInfo._hWaitableTimer, &m_liBeginTime, m_lTimePeriod, NULL, NULL, TRUE);//支持唤醒计算机<TRUE> //CloseHandle(m_FtpInfo._hWaitableTimer);//在本对象析构的时候才关闭这个句柄 return TRUE; }
int evfilt_timer_knote_create(struct filter *filt, struct knote *kn) { HANDLE th; LARGE_INTEGER liDueTime; kn->kev.flags |= EV_CLEAR; th = CreateWaitableTimer(NULL, FALSE, NULL); if (th == NULL) { dbg_lasterror("CreateWaitableTimer()"); return (-1); } dbg_printf("created timer handle %p", th); convert_msec_to_filetime(&liDueTime, kn->kev.data); // XXX-FIXME add completion routine to this call if (!SetWaitableTimer(th, &liDueTime, (LONG)( (kn->kev.flags & EV_ONESHOT) ? 0 : kn->kev.data ), NULL, NULL, FALSE)) { dbg_lasterror("SetWaitableTimer()"); CloseHandle(th); return (-1); } kn->data.handle = th; RegisterWaitForSingleObject(&kn->kn_event_whandle, th, evfilt_timer_callback, kn, INFINITE, 0); knote_retain(kn); return (0); }
static void newhandler_08_timer_thread(void) { LARGE_INTEGER DueTime; //char sout[100]; if(!int08_timer_handle){ int08_timer_handle=CreateWaitableTimer(NULL,0,NULL); if(int08_timer_handle){ DueTime.QuadPart=-(int08_timer_period*10000); SetWaitableTimer(int08_timer_handle,&DueTime,(int08_timer_period+1)/2,NULL,NULL,0); }else{ } } do{ funcbit_smp_value_increment(int08counter); //sprintf(sout,"c:%5d tp:%d",int08counter,int08_timer_period); //display_message(1,0,sout); WaitForSingleObject(int08_timer_handle,int08_timer_period); }while(mpxplay_timed_functions); if(int08_timer_handle){ CancelWaitableTimer(int08_timer_handle); CloseHandle(int08_timer_handle); int08_timer_handle=NULL; } }
/*void _USERENTRY LongThreadProc (LPVOID lParam) { while (longReference>0) { IMLOG("threadLONG"); CtrlEx->WMProcess(); SleepEx(500 , 1); } threadLong=0; } */ int StartLong(sDIALOG_long * sd) { // HANDLE timer; // if (dlg) { // timer = CreateWaitableTimer(0,0,0); // } else timer = timerLong; IMLOG("* Start Long %s" , (sd->flag & DLONG_BLOCKING)? "with non-BLOCKING.timer" : "Dlg w/o timer"); if (!K_CHECK_PTR(sd)) { IMDEBUG(DBG_ERROR, "Bad dLong pointer %x", sd); return 0; } LARGE_INTEGER lDueTime; if (sd->timeoutProc) { sd->timeoutProc(TIMEOUTT_START , sd); sd->timeoutHandle = CreateWaitableTimer(0,0,0); sd->timeoutPassed = 0; lDueTime.QuadPart = -10000 * TIMEOUT_INTERVAL; SetWaitableTimer(sd->timeoutHandle , &lDueTime , TIMEOUT_INTERVAL,TimeoutTimerProc, sd , 0); } if (sd->flag & DLONG_BLOCKING) { longReference++; lDueTime.QuadPart = 0; SetWaitableTimer(timerLong , &lDueTime , 50 ,LongTimerProc, sd?sd->handle:0 , 0); CtrlEx->WMProcess(); // if (!threadLong) threadLong=_beginthread(LongThreadProc,0,0); } return 1; }
static void init_timer(int seconds) { timer = CreateWaitableTimer(NULL, TRUE, "file_rotation_timer"); if (timer == NULL) die("CreateWaitableTimer failed"); set_timer(seconds); }
bool WTimer::Create(LPSECURITY_ATTRIBUTES lpTimerAttributes, BOOL bManualReset, LPCTSTR lpTimerName) { Close(); m_Timer = CreateWaitableTimer(lpTimerAttributes, bManualReset, lpTimerName); return(m_Timer != NULL); }
int TestSynchWaitableTimerAPC(int argc, char* argv[]) { HANDLE hTimer; BOOL bSuccess; LARGE_INTEGER due; APC_DATA* apcData; apcData = (APC_DATA*) malloc(sizeof(APC_DATA)); g_Event = CreateEvent(NULL, TRUE, FALSE, NULL); hTimer = CreateWaitableTimer(NULL, FALSE, NULL); if (!hTimer) return -1; due.QuadPart = -15000000LL; /* 1.5 seconds */ apcData->StartTime = GetTickCount(); bSuccess = SetWaitableTimer(hTimer, &due, 2000, TimerAPCProc, apcData, FALSE); if (!bSuccess) return -1; if (WaitForSingleObject(g_Event, INFINITE) != WAIT_OBJECT_0) { printf("WaitForSingleObject failed (%d)\n", GetLastError()); return -1; } CloseHandle(hTimer); CloseHandle(g_Event); free(apcData); return 0; }
static int systimer_create(systimer_t* id, unsigned int period, int oneshot, systimer_proc callback, void* cbparam) { LARGE_INTEGER tv; timer_context_t* ctx; ctx = (timer_context_t*)malloc(sizeof(timer_context_t)); if(!ctx) return -ENOMEM; memset(ctx, 0, sizeof(timer_context_t)); ctx->callback = callback; ctx->cbparam = cbparam; ctx->timerId = CreateWaitableTimer(NULL, FALSE, NULL); if(0 == ctx->timerId) { free(ctx); return -(int)GetLastError(); } tv.QuadPart = -10000L * period; // in 100 nanosecond intervals if(!SetWaitableTimer(ctx->timerId, &tv, oneshot?0:period, timer_schd_worker, ctx, FALSE)) { CloseHandle(ctx->timerId); free(ctx); return -(int)GetLastError(); } *id = (systimer_t)ctx; return 0; }
void start_benchmark(struct benchmark_st * st) { memset(st, 0, sizeof(*st)); #ifndef _WIN32 st->old_handler = signal (SIGALRM, alarm_handler); #endif gettime (&st->start); benchmark_must_finish = 0; #if defined(_WIN32) st->wtimer = CreateWaitableTimer (NULL, TRUE, NULL); if (st->wtimer == NULL) { fprintf (stderr, "error: CreateWaitableTimer %u\n", GetLastError ()); exit(1); } st->wthread = CreateThread (NULL, 0, alarm_handler, &st->wtimer, 0, NULL); if (st->wthread == NULL) { fprintf (stderr, "error: CreateThread %u\n", GetLastError ()); exit(1); } st->alarm_timeout.QuadPart = (BSECS) * 10000000; if (SetWaitableTimer (st->wtimer, &st->alarm_timeout, 0, NULL, NULL, FALSE) == 0) { fprintf (stderr, "error: SetWaitableTimer %u\n", GetLastError ()); exit(1); } #else alarm (BSECS); #endif }
int freespace_private_discoveryThreadInit() { HANDLE thread; if (freespace_instance_->window_ != NULL) { return FREESPACE_ERROR_BUSY; } // Create the timer used to indicated device rescan is required. freespace_instance_->discoveryEvent_ = CreateWaitableTimer(NULL, TRUE, NULL); if (freespace_instance_->discoveryEvent_ == NULL) { return FREESPACE_ERROR_UNEXPECTED; } // Need to scan a first time. freespace_instance_->needToRescanDevicesFlag_ = TRUE; // Create the hidden window freespace_instance_->discoveryTheadStatus_ = FREESPACE_SUCCESS; thread = CreateThread(NULL, 0, discoveryWindow, NULL, 0, NULL); if (thread == NULL) { freespace_instance_->discoveryTheadStatus_ = FREESPACE_ERROR_COULD_NOT_CREATE_THREAD; return FREESPACE_ERROR_COULD_NOT_CREATE_THREAD; } return FREESPACE_SUCCESS; }
void TRI_usleep(unsigned long waitTime) { int result; HANDLE hTimer = NULL; // stores the handle of the timer object LARGE_INTEGER wTime; // essentially a 64bit number wTime.QuadPart = waitTime * 10; // *10 to change to microseconds wTime.QuadPart = -wTime.QuadPart; // negative indicates relative time elapsed, // Create an unnamed waitable timer. hTimer = CreateWaitableTimer(NULL, 1, NULL); if (hTimer == NULL) { // no much we can do at this low level return; } if (GetLastError() == ERROR_ALREADY_EXISTS) { abort(); } // Set timer to wait for indicated micro seconds. if (!SetWaitableTimer(hTimer, &wTime, 0, NULL, NULL, 0)) { // no much we can do at this low level return; } // Wait for the timer result = WaitForSingleObject(hTimer, INFINITE); if (result != WAIT_OBJECT_0) { abort(); } CloseHandle(hTimer); // todo: go through what the result is e.g. WAIT_OBJECT_0 return; }
/* procedure to poll the event queue for timer events, run by the clock thread; on a timer event, call "send_interrupt()" to run the system thread's clock handler routine */ DWORD WINAPI clock_poll(LPVOID arg) { #ifdef WINCE for(;;) { Sleep(PERIOD/1000); /* sleep requires time in milliseconds */ send_interrupt(CLOCK_INTERRUPT_TYPE, NULL); } #else LARGE_INTEGER i; HANDLE timer; /* HANDLE thread = GetCurrentThread(); */ char name[64]; sprintf(name, "timer %d", pid); timer = CreateWaitableTimer(NULL, TRUE, name); assert(timer != NULL); for (;;) { i.QuadPart = -PERIOD*10; /* NT timer values are in hundreds of nanoseconds */ AbortOnError(SetWaitableTimer(timer, &i, 0, NULL, NULL, FALSE)); if (WaitForSingleObject(timer, INFINITE) == WAIT_OBJECT_0) { if (DEBUG) kprintf("CLK: clock tick.\n"); send_interrupt(CLOCK_INTERRUPT_TYPE, NULL); } } #endif /* never reached */ return 0; }
void asio_event_subscribe(asio_event_t* ev) { if((ev == NULL) || (ev->flags == ASIO_DISPOSABLE) || (ev->flags == ASIO_DESTROYED)) return; asio_backend_t* b = asio_get_backend(); if(ev->noisy) asio_noisy_add(); if((ev->flags & ASIO_TIMER) != 0) { // Need to start a timer. // We can create it here but not start it. That must be done in the // background thread because that's where we want the fire APC to happen. // ev->data is initially the time (in nsec) and ends up as the handle. ev->timer = CreateWaitableTimer(NULL, FALSE, NULL); send_request(ev, ASIO_SET_TIMER); } else if((ev->flags & ASIO_SIGNAL) != 0) { if(ev->nsec < MAX_SIGNAL) send_request(ev, ASIO_SET_SIGNAL); } else if(ev->fd == 0) { // Need to subscribe to stdin send_request(ev, ASIO_STDIN_NOTIFY); } }
int main() { HANDLE hTimer = NULL; LARGE_INTEGER liDueTime; // рт100дицКн╙╥ж╦Н liDueTime.QuadPart = -100000000LL; // Create an unnamed waitable timer. hTimer = CreateWaitableTimer(NULL, TRUE, NULL); if (NULL == hTimer) { printf("CreateWaitableTimer failed (%d)\n", GetLastError()); return 1; } printf("Waiting for 10 seconds...\n"); // Set a timer to wait for 10 seconds. if (!SetWaitableTimer(hTimer, &liDueTime, 0, NULL, NULL, 0)) { printf("SetWaitableTimer failed (%d)\n", GetLastError()); return 2; } // Wait for the timer. if (WaitForSingleObject(hTimer, INFINITE) != WAIT_OBJECT_0) { printf("WaitForSingleObject failed (%d)\n", GetLastError()); } else { printf("Timer was signaled.\n"); } system("pause"); return 0; }
void main(void) { const int nTimerUnitsPerSecond = 10000000; int cAbrasionCount = 0; SYSTEMTIME st; LARGE_INTEGER li; HANDLE hTimer = CreateWaitableTimer(NULL, FALSE, NULL); GetLocalTime(&st); printf("Start time: \t\t%.2d:%.2d:%.2d\n\n", st.wHour, st.wMinute, st.wSecond); li.QuadPart = -(15 * nTimerUnitsPerSecond); if (SetWaitableTimer(hTimer, &li, 15 * 1000, NULL, NULL, FALSE)){ while (TRUE){ GetLocalTime(&st); cAbrasionCount++; printf("%d.Timer abrasion: \t%.2d:%.2d:%.2d\n", cAbrasionCount, st.wHour, st.wMinute, st.wSecond); hSecThread = CreateThread(NULL, 0, ThreadFunc1, (LPVOID)cAbrasionCount, 0, &dwSecThreadId); DWORD dw = WaitForSingleObject(hTimer, INFINITE); TerminateThread(hSecThread, 1001); hSecThread = NULL; dwSecThreadId = 0; } } }
DWORD WINAPI th_TimeOut( LPVOID lp ) { HANDLE hTimer = CreateWaitableTimer( NULL, FALSE, NULL ) ; LARGE_INTEGER li = {0, } ; _Temp_timerentry entry ; _j_Templet_Timer * pTimer ; pTimer = (_j_Templet_Timer*)lp ; int pos = 0 ; _h_DS_Com * pDSCom ; DWORD curTime ; printf( " => Start Timer\n" ) ; SetWaitableTimer( hTimer, &li, 50, NULL, NULL, TRUE ) ; while(pTimer->bThreadRun) { try{ WaitForSingleObject( hTimer, INFINITE ) ; curTime = timeGetTime() ; while ( pTimer->Get_TimeMessage( curTime, entry ) == true ) { pDSCom = (_h_DS_Com*)entry.pDS_Com ; if( !pDSCom ) continue ; pos = 1 ; if( (pDSCom->get_id() > 0) && (pDSCom->m_pFriendInfo == NULL) ) // 접속만 하고 아직까지 로그인을 안한 사용자다.. 끊어버려라. { pos = 2 ; #ifdef _TRACE_ g_pTrace->OutputString( _TRACE_CLASS_SYSTEM, "[KICK OUT] Overtime connection client \n") ; #endif pos = 3 ; pDSCom->DisConnect() ; } } } catch (...) { ::PrintConsole("[EXCEPTION] th_TimeOut pos:%d\n", pos) ; } } ::PrintConsole("[THREAD EXIT] th_TimeOut \n") ; return 0 ; }
ofTimer::ofTimer() :nanosPerPeriod(0) #ifdef TARGET_WIN32 ,hTimer(CreateWaitableTimer(NULL, TRUE, NULL)) #endif { }
ofTimer::ofTimer() :nanosPerPeriod(0) #ifdef TARGET_WIN32 ,hTimer(CreateWaitableTimer(nullptr, TRUE, nullptr)) #endif { }
void P_CTOR_Timer_IMPL(PRT_MACHINEINST *context, PRT_VALUE *value) { printf("Entering P_CTOR_Timer_IMPL\n"); TimerContext *timerContext = (TimerContext *)malloc(sizeof(TimerContext)); timerContext->client = PrtCloneValue(value); timerContext->timer = CreateWaitableTimer(NULL, TRUE, NULL); PrtAssert(timerContext->timer != NULL, "CreateWaitableTimer failed"); context->extContext = timerContext; }
void usleep(long long usec) { HANDLE timer = 0; LARGE_INTEGER ft = { 0 }; ft.QuadPart = -(10 * usec); // Convert to 100 nanosecond interval, negative value indicates relative time timer = CreateWaitableTimer(NULL, TRUE, NULL); SetWaitableTimer(timer, &ft, 0, NULL, NULL, 0); WaitForSingleObject(timer, INFINITE); CloseHandle(timer); }
int main( int argc, char *argv [] ) { LARGE_INTEGER lint; DWORD Written; COORD Coord = { 0, 0 }; myself = GetModuleHandle(NULL); GetConsoleScreenBufferInfo (GetStdHandle(STD_OUTPUT_HANDLE), &ScreenBufferInfo); ScreenBufferInfo.dwSize.X = ScreenBufferInfo.srWindow.Right - ScreenBufferInfo.srWindow.Left + 1; ScreenBufferInfo.dwSize.Y = ScreenBufferInfo.srWindow.Bottom - ScreenBufferInfo.srWindow.Top + 1; ScreenBuffer = CreateConsoleScreenBuffer( GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL ); if (INVALID_HANDLE_VALUE == ScreenBuffer) { _ftprintf( stderr, _TEXT("%s: could not create a new screen buffer\n"), app_name ); return EXIT_FAILURE; } // Fill buffer with black background FillConsoleOutputAttribute( ScreenBuffer, 0, ScreenBufferInfo.dwSize.X * ScreenBufferInfo.dwSize.Y, Coord, &Written ); WaitableTimer = CreateWaitableTimer( NULL, FALSE, NULL ); if( WaitableTimer == INVALID_HANDLE_VALUE ) { printf( "CreateWaitabletimer() failed\n" ); return 1; } lint.QuadPart = -2000000; if( SetWaitableTimer( WaitableTimer, &lint, 200, NULL, NULL, FALSE ) == FALSE ) { printf( "SetWaitableTimer() failed: 0x%lx\n", GetLastError() ); return 2; } SetConsoleActiveScreenBuffer(ScreenBuffer); MainLoop(); CloseHandle(ScreenBuffer); return EXIT_SUCCESS; }
unsigned __stdcall ManageThread( void* Param ) { HANDLE hGlobal = CreateWaitableTimer( NULL, FALSE, L"ZZVBN-ARARA-12" ); //Global DB update timer HANDLE hLocal = CreateWaitableTimer( NULL, FALSE, L"ZZVBN-ARARA-36" ); //Local DB update timer //--------------------------------------------------------- LARGE_INTEGER liGlobalUpd; LARGE_INTEGER liLocalUpd; const int nTimeUnits = 10000000; liGlobalUpd.QuadPart = -( 60/*1 hour*/ * nTimeUnits ); liLocalUpd.QuadPart = -( 10/*5 minutes*/ * nTimeUnits ); //--------------------------------------------------------- //set timers here, for global and local updates SetWaitableTimer( hGlobal, &liGlobalUpd, 60/*1 hour*/ * 1000, NULL, NULL, FALSE ); SetWaitableTimer( hLocal, &liLocalUpd, 10/*5 minutes*/ *1000, NULL, NULL, FALSE ); //--------------------------------------------------------- while( true ) { //capture critical section and free it every 5 minutes, so Local Update Thread can update values EnterCriticalSection( &csUpdater ); bInitiated = true; WaitForSingleObject( hLocal, INFINITE ); LeaveCriticalSection( &csUpdater ); Sleep( 200 ); } return 0; }