Bonjour,

J'ai un petit problème avec la gestion d'un Timer.

Je vous expose mon problème :
Je fais un WaitForMultipleObjects, puis je fais un SetWaitableTimer sur un handle. Le problème c'est que je n'arrive pas à faire un ResetEvent sur le Handle à qui j'ai fait mon SetWaitableTimer. Pourtant je fais bien un CreateWaitableTimer en FALSE pour qu'il fasse un ResetEvent automatiquement et j'ai aussi essayé avec un TRUE.

Mon but :
Afficher un texte pendant un temps n secondes. Si j'envoi plusieurs textes pendant ce temps n secondes, je stocke les messages suivants et je les afficherai après le temps n secondes, les uns après les autres.

Mais le résultat actuel :
J'affiche bien le premier texte pendant n secondes. Mais, si j'envoi plusieurs textes pendant ce temps, les textes suivants arrivent après le temps n secondes (tout va bien juste qu'ici !!!!) mais, il arrive tous en même temps.

voici mon code source:
Voici la fonction où je fais un waitformultipleobjects, un setwaitable
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
void CDisplay::TimeDisplayProc(void* pThis)
{
	CDisplay* pDis=(CDisplay*)pThis;

	// Return code of waitformultipleobjects
	DWORD l_dwWaitReturn;

	// Define handle array to manage start of timer and stop of thread
	HANDLE l_EventTab[3] = {0, 0, 0};

	// Specifies when the state of the timer is to be set to signaled, in 100 nanosecond intervals.
	LARGE_INTEGER liDueTime;

	// Create a waitable timer 
	HANDLE l_TimerHandle = NULL;

	l_TimerHandle = CreateWaitableTimer(0, FALSE, "TimeDisplayTimer");
	if (!l_TimerHandle)
		pDis->LogDebug(pDis->m_sPackage, pDis->m_sComponent, "TimeDisplayProc", "l_TimerHandle failed", __FILE__, __LINE__);
	
	// Initialise event array
	l_EventTab[0] = pDis->m_hStartTimer;
	l_EventTab[1] = l_TimerHandle;
	l_EventTab[2] = pDis->m_hEndTimeDisplayProc;

	bool l_bRun = true;
	while (l_bRun)
	{
		// Wait for the start of timer
		l_dwWaitReturn = WaitForMultipleObjects(3, l_EventTab, FALSE, INFINITE);

		switch(l_dwWaitReturn)
		{
			case WAIT_OBJECT_0:
				// Start timer
				{
					liDueTime.QuadPart = -15000000; // =15secondes

					// Set a timer to wait for N seconds.
					if (!SetWaitableTimer(l_EventTab[1], &liDueTime, 0, NULL, NULL, FALSE))
						pDis->LogDebug(pDis->m_sPackage, pDis->m_sComponent, "TimeDisplayProc", "SetWaitableTimer failed", __FILE__, __LINE__);

					pDis->m_bDisplayInProgress = true;
				}
				break;
			case WAIT_OBJECT_0 + 1:
				// Time is done
				{
					EnterCriticalSection(&pPID->m_critsecDataProtection);
					
 					if (!pDis->m_DisplayList.empty())
					{
						std::string stext = pDis->m_DisplayList.front().text;
						int minTime = pDis->m_DisplayList.front().minDuration;
						pDis->m_DisplayList.pop_front();

						pDis->m_bDisplayInProgress = false;
						pDis->_PrintText(stext, minTime);
					}
					else
						pDis->m_bDisplayInProgress = true;

					LeaveCriticalSection(&pDis->m_critsecDataProtection);				
				}
				break;
			case WAIT_OBJECT_0 + 2:
				// End requested
				{
					l_bRun = false;
					CloseHandle(pDis->m_hStartTimer);
					CloseHandle(pDis->m_hEndTimeDisplayProc);
					CloseHandle(l_TimerHandle);
				}
				break;
			case WAIT_FAILED:
				{
					pDis->LogDebug(pPID->m_sPackage, pPID->m_sComponent, "TimeDisplayProc", "WaitForMultipleObjects failed", __FILE__, __LINE__);
				}
				break;
			default:
				break;
		}
	}
}


Cette fonction permet d'afficher un texte ou sinon je stocke le texte en attendant la fin du timer.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Fonction pour l'affichage
FRESULT CDisplay::_PrintText(std::string sText, int uiTime)
{
	EnterCriticalSection(&m_critsecDataProtection);
	FRESULT err = ERROR_SUCCESS;

	m_sDispInfo.text = sText.c_str();
	m_sDispInfo.minDuration = -uiTime;

	if (m_bDisplayInProgress)
		m_DisplayList.push_back(m_sDispInfo);
	else
	{	
		err = m_DisplayLowLevel->PrintText(m_sDispInfo.text, EXEC_DP_PRINTLC);
		LogDebug(m_sPackage, m_sComponent, "_PrintText", m_sDispInfo.text, __FILE__, __LINE__);

		m_bDisplayInProgress = true;
		SetEvent(m_hStartTimer);
	}

	LeaveCriticalSection(&m_critsecDataProtection);
	return err;
}

Merci d'avance,