64,647
社区成员
发帖
与我相关
我的任务
分享
DWORD WINAPI KeepAliveThread(LONG ID)
{
TCHAR szError[255];
HANDLE hTimer;
__int64 qwDueTime;
LARGE_INTEGER liDueTime;
/* ResvTimer */
CString tempStr;
tempStr.Format("keepaliveTimer_%x",Local_IP);
if ( hTimer = CreateWaitableTimer(NULL, FALSE,(LPCSTR)tempStr ) )
{
// Create an integer that will be used to signal the timer
// 5 seconds from now.
qwDueTime = (-5) * _SECOND;
// Copy the relative time into a LARGE_INTEGER.
liDueTime.LowPart = (DWORD) ( qwDueTime & 0xFFFFFFFF );
liDueTime.HighPart = (LONG) ( qwDueTime >> 32 );
if ( SetWaitableTimer(hTimer, &liDueTime, TIMER_KEEPALIVE/*Periodic timer interval of 30 seconds*/,
KeepAliveProc,NULL, FALSE ) ) //每30秒执行一次这个保活函数
{
TRACE("Called the KeepAliveProc to send keep alive messages .\n");
while (RunFlag)
{
SleepEx( INFINITE,TRUE );
}
}
else
{
wsprintf( szError, "SetWaitableTimer failed with Error \
%d.", GetLastError() );
MessageBox( NULL, szError, "Error", MB_ICONEXCLAMATION );
}
CloseHandle( hTimer ); // END of timer
}
return 0;
}