timer start problem
-
Hallo, I need to start a timer like the following to measure the time that my appliction requires to do someting: void CMiniClass :: DoSomething() { theApp.m_pMainWnd ->SetTimer (MY_TIMER,1000,NULL); while (i > 0) { DoStuff(); } //theApp.m_pMainWnd ->KillTimer (MY_TIMER); } in the CMainFrame.cpp i overrode the OnTimer() from the baseclass: void CMainFrame::OnTimer(UINT nIDEvent) { m_bFlagStartTimer = true; CFrameWnd::OnTimer(nIDEvent); CString strTimer(_T("")); m_nSeconds++; if(m_nSeconds == 60) { m_nMinutes++; m_nSeconds = 0; } if(m_nMinutes == 60) { m_nHours++; m_nMinutes = 0; } if(m_nHours == 24) { m_nHours = 0; } strTimer.Format("%d:%d:%d", m_nHours, m_nMinutes, m_nSeconds); MessageBox(strTimer,0,0); } the problem is the application starts the Timer(in the Messagebox) after he finished the while-loop,so i can not know how long my appliction was BUSY with this loop, and if i activate theApp.m_pMainWnd ->KillTimer (MY_TIMER); the Timer would be KILLED and then the while-llop starts, i need to do this without using Thread. Please help to fix this problem. Thanks.
-
Hallo, I need to start a timer like the following to measure the time that my appliction requires to do someting: void CMiniClass :: DoSomething() { theApp.m_pMainWnd ->SetTimer (MY_TIMER,1000,NULL); while (i > 0) { DoStuff(); } //theApp.m_pMainWnd ->KillTimer (MY_TIMER); } in the CMainFrame.cpp i overrode the OnTimer() from the baseclass: void CMainFrame::OnTimer(UINT nIDEvent) { m_bFlagStartTimer = true; CFrameWnd::OnTimer(nIDEvent); CString strTimer(_T("")); m_nSeconds++; if(m_nSeconds == 60) { m_nMinutes++; m_nSeconds = 0; } if(m_nMinutes == 60) { m_nHours++; m_nMinutes = 0; } if(m_nHours == 24) { m_nHours = 0; } strTimer.Format("%d:%d:%d", m_nHours, m_nMinutes, m_nSeconds); MessageBox(strTimer,0,0); } the problem is the application starts the Timer(in the Messagebox) after he finished the while-loop,so i can not know how long my appliction was BUSY with this loop, and if i activate theApp.m_pMainWnd ->KillTimer (MY_TIMER); the Timer would be KILLED and then the while-llop starts, i need to do this without using Thread. Please help to fix this problem. Thanks.
You shouldn't be using a timer here. You should ideally get the time first, start your job, get the time again after you're job completes and then compare the first and second time.
«_Superman_» I love work. It gives me something to do between weekends.
-
Hallo, I need to start a timer like the following to measure the time that my appliction requires to do someting: void CMiniClass :: DoSomething() { theApp.m_pMainWnd ->SetTimer (MY_TIMER,1000,NULL); while (i > 0) { DoStuff(); } //theApp.m_pMainWnd ->KillTimer (MY_TIMER); } in the CMainFrame.cpp i overrode the OnTimer() from the baseclass: void CMainFrame::OnTimer(UINT nIDEvent) { m_bFlagStartTimer = true; CFrameWnd::OnTimer(nIDEvent); CString strTimer(_T("")); m_nSeconds++; if(m_nSeconds == 60) { m_nMinutes++; m_nSeconds = 0; } if(m_nMinutes == 60) { m_nHours++; m_nMinutes = 0; } if(m_nHours == 24) { m_nHours = 0; } strTimer.Format("%d:%d:%d", m_nHours, m_nMinutes, m_nSeconds); MessageBox(strTimer,0,0); } the problem is the application starts the Timer(in the Messagebox) after he finished the while-loop,so i can not know how long my appliction was BUSY with this loop, and if i activate theApp.m_pMainWnd ->KillTimer (MY_TIMER); the Timer would be KILLED and then the while-llop starts, i need to do this without using Thread. Please help to fix this problem. Thanks.
susanne1 wrote:
I need to start a timer like the following to measure the time that my appliction requires to do someting
You're using the wrong sort of timer - the windows timer sends one of your windows a WM_TIMER message when the time you wanted has expired. You imply you want to measure how long something took to run. They way to do that is to find the time when the activity starts, the time when it ends and determine the difference between them. I generally use the high-resolution counter[^] for that.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
You shouldn't be using a timer here. You should ideally get the time first, start your job, get the time again after you're job completes and then compare the first and second time.
«_Superman_» I love work. It gives me something to do between weekends.
i used this code but the problem it starts first when the appliction has finished the job. CFrameWnd::OnTimer(nIDEvent); CTime timer; CString strTimer (_T("")); timer = CTime::GetCurrentTime (); if(((m_nSeconds = timer.GetSecond ()) == 0) && (m_bFlagTimer == true)) { m_nMinutes++; } if(((timer.GetMinute ()) == 0) && (m_bFlagTimer == true)) { m_nHours++; } wsprintf((LPTSTR)strTimer.GetString (),"%02i:%02i:%02i",m_nHours, m_nMinutes, m_nSeconds); m_wndStatusBar.SetPaneText(5,LPCSTR(strTimer.GetString ()),true i need to count parallel to the task when it runs.
-
susanne1 wrote:
I need to start a timer like the following to measure the time that my appliction requires to do someting
You're using the wrong sort of timer - the windows timer sends one of your windows a WM_TIMER message when the time you wanted has expired. You imply you want to measure how long something took to run. They way to do that is to find the time when the activity starts, the time when it ends and determine the difference between them. I generally use the high-resolution counter[^] for that.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
i used this code but the problem it starts first when the appliction has finished the job. CFrameWnd::OnTimer(nIDEvent); CTime timer; CString strTimer (_T("")); timer = CTime::GetCurrentTime (); if(((m_nSeconds = timer.GetSecond ()) == 0) && (m_bFlagTimer == true)) { m_nMinutes++; } if(((timer.GetMinute ()) == 0) && (m_bFlagTimer == true)) { m_nHours++; } wsprintf((LPTSTR)strTimer.GetString (),"%02i:%02i:%02i",m_nHours, m_nMinutes, m_nSeconds); m_wndStatusBar.SetPaneText(5,LPCSTR(strTimer.GetString ()),true i need to count parallel to the task when it runs.
-
i used this code but the problem it starts first when the appliction has finished the job. CFrameWnd::OnTimer(nIDEvent); CTime timer; CString strTimer (_T("")); timer = CTime::GetCurrentTime (); if(((m_nSeconds = timer.GetSecond ()) == 0) && (m_bFlagTimer == true)) { m_nMinutes++; } if(((timer.GetMinute ()) == 0) && (m_bFlagTimer == true)) { m_nHours++; } wsprintf((LPTSTR)strTimer.GetString (),"%02i:%02i:%02i",m_nHours, m_nMinutes, m_nSeconds); m_wndStatusBar.SetPaneText(5,LPCSTR(strTimer.GetString ()),true i need to count parallel to the task when it runs.
There is no point reposting the same code. there was an answer given by somebody. try that out. if you get stuck as again. you will get assistance
-
i used this code but the problem it starts first when the appliction has finished the job. CFrameWnd::OnTimer(nIDEvent); CTime timer; CString strTimer (_T("")); timer = CTime::GetCurrentTime (); if(((m_nSeconds = timer.GetSecond ()) == 0) && (m_bFlagTimer == true)) { m_nMinutes++; } if(((timer.GetMinute ()) == 0) && (m_bFlagTimer == true)) { m_nHours++; } wsprintf((LPTSTR)strTimer.GetString (),"%02i:%02i:%02i",m_nHours, m_nMinutes, m_nSeconds); m_wndStatusBar.SetPaneText(5,LPCSTR(strTimer.GetString ()),true i need to count parallel to the task when it runs.
What you want to do is something like this (using code from you original post):
void CMiniClass :: DoSomething()
{
LARGE_INTEGER startTime, endTime;
QueryPerformanceCounter(&startTime);
while (i > 0)
{
DoStuff();
}
QueryPerformanceCounter(&endTime);
LARGE_INTEGER elapsedTime;
elapsedTime.QuadPart = endTime.QuadPart - startTime.QuadPart;
LARGE_INTEGER timerFreq;
QueryPerformanceFrequency(&timerFreq);
const double elapsedTimeInSeconds = (double)elapsedTime.QuadPart / (double)timerFreq.QuadPart;
}Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p