Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Alternative for TIMERs in MFC??

Alternative for TIMERs in MFC??

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestioncode-review
10 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kiran Satish
    wrote on last edited by
    #1

    I am having a dialog box application (main dialog box in which many other child dialog boxes are created) in which I am having a closed loop function which does a series of other functions(doing some computations and updating some dialog boxes) continuously untill the user stops. For this we are using TIMERs, but using TIMERs I see there is atleast 10ms delay between the end of first TIMER to the start of next TIMER. We are trying to improve our closed loop frequency and I am not able to reduce this delay?? Is there any other better way rather than using TIMERs, like using threads (but the problem is when I tried using threads before, the interface doesnt respond anymore once the thread has started). thanks in advance.

    PKNT

    C T J 3 Replies Last reply
    0
    • K Kiran Satish

      I am having a dialog box application (main dialog box in which many other child dialog boxes are created) in which I am having a closed loop function which does a series of other functions(doing some computations and updating some dialog boxes) continuously untill the user stops. For this we are using TIMERs, but using TIMERs I see there is atleast 10ms delay between the end of first TIMER to the start of next TIMER. We are trying to improve our closed loop frequency and I am not able to reduce this delay?? Is there any other better way rather than using TIMERs, like using threads (but the problem is when I tried using threads before, the interface doesnt respond anymore once the thread has started). thanks in advance.

      PKNT

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #2

      Kiran Satish wrote:

      like using threads (but the problem is when I tried using threads before, the interface doesnt respond anymore once the thread has started)

      That means you need to properly using threads. How are you using timers? How did you use threads?

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

      K 1 Reply Last reply
      0
      • K Kiran Satish

        I am having a dialog box application (main dialog box in which many other child dialog boxes are created) in which I am having a closed loop function which does a series of other functions(doing some computations and updating some dialog boxes) continuously untill the user stops. For this we are using TIMERs, but using TIMERs I see there is atleast 10ms delay between the end of first TIMER to the start of next TIMER. We are trying to improve our closed loop frequency and I am not able to reduce this delay?? Is there any other better way rather than using TIMERs, like using threads (but the problem is when I tried using threads before, the interface doesnt respond anymore once the thread has started). thanks in advance.

        PKNT

        T Offline
        T Offline
        toxcct
        wrote on last edited by
        #3

        this is NOT because of the MFC's Timer (which is in fact a wrapper to Win32), but because Windows is NOT a Real Time OS... so you cannot expect much efficiency from there.

        [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

        K 1 Reply Last reply
        0
        • C CPallini

          Kiran Satish wrote:

          like using threads (but the problem is when I tried using threads before, the interface doesnt respond anymore once the thread has started)

          That means you need to properly using threads. How are you using timers? How did you use threads?

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

          K Offline
          K Offline
          Kiran Satish
          wrote on last edited by
          #4

          Yes... I know I haven't used threads in proper way in this particular application ;P . Well I used them in more sumple way, once the user clicks on 'Close Loop' button on one of the dialog boxes, I start a thread that does all the necessary work, but I remember it giving errors when I send/post messages to dialog boxes (but I am not sure) and the interface doesnt respnd anymore to user inputs. Coming to TIMERs, here is how we are using currently- //This is the code for the close loop user interface button void CAnalysisDlg::OnCloseloop() { CButton *ClButton; HICON icn; ClButton = (CButton *)GetDlgItem(IDB_CLOSELOOP); icn = ClButton->GetIcon(); if(icn == AfxGetApp()->LoadIcon(IDI_CLOSELOOP)) { ClButton->SendMessage(BM_SETIMAGE,IMAGE_ICON,(LPARAM)AfxGetApp()->LoadIcon(IDI_LOOPCLOSED)); if(parent->closeLoop() == FALSE) { ClButton->SendMessage(BM_SETIMAGE,IMAGE_ICON,(LPARAM)AfxGetApp()->LoadIcon(IDI_CLOSELOOP)); } } else { KillTimer(1); parent->Uncheck_Closeloop(); } } //This code goes into parent(main) dialog box BOOL CMainDlg::closeLoop() { //do some intializations and calculations here if(OnAutoMeasure()==FALSE) return FALSE; } BOOL CMainDlg::OnAutoMeasure() { //calculate the frequency of closed loop //do closed loop functions and update other dialog boxes as necessary //if there is nay error it returns false SetTimer(1,1,NULL); return TRUE; } void CMainDlg::OnTimer(UINT nIDEvent) { CButton *ClButton; HICON icn; KillTimer(1); ClButton = (CButton *)tbdisp->GetDlgItem(IDB_CLOSELOOP); icn = ClButton->GetIcon(); if(icn == AfxGetApp()->LoadIcon(IDI_LOOPCLOSED)) { if(closeloopsafety <= NUM_FALSE_RETURN_AUTOMEASURE) { if(OnAutoMeasure()==FALSE) Uncheck_Closeloop(); } else Uncheck_Closeloop(); } CDialog::OnTimer(nIDEvent); } I hope the code wont be too much of confusion :). But that how its basically works now.

          PKNT

          1 Reply Last reply
          0
          • T toxcct

            this is NOT because of the MFC's Timer (which is in fact a wrapper to Win32), but because Windows is NOT a Real Time OS... so you cannot expect much efficiency from there.

            [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

            K Offline
            K Offline
            Kiran Satish
            wrote on last edited by
            #5

            Yes.. its true. But I never had much of problems using threads in MFC, they used to work better. But well you can't compare it with other real-time OSes like Linux and other packages that you can get that makes Windows as real-time OS though :) .

            PKNT

            T J 2 Replies Last reply
            0
            • K Kiran Satish

              Yes.. its true. But I never had much of problems using threads in MFC, they used to work better. But well you can't compare it with other real-time OSes like Linux and other packages that you can get that makes Windows as real-time OS though :) .

              PKNT

              T Offline
              T Offline
              toxcct
              wrote on last edited by
              #6

              but maybe your processor is overloaded in kernel mode...

              [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

              K 1 Reply Last reply
              0
              • T toxcct

                but maybe your processor is overloaded in kernel mode...

                [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                K Offline
                K Offline
                Kiran Satish
                wrote on last edited by
                #7

                Good point, but I have 8 cores and I barely use one core at full clock (while running all our applications at the same time) and to say windows is not bad in scheduling processes on multi core systems and distributes evenly if not overloading :omg: .

                PKNT

                1 Reply Last reply
                0
                • K Kiran Satish

                  I am having a dialog box application (main dialog box in which many other child dialog boxes are created) in which I am having a closed loop function which does a series of other functions(doing some computations and updating some dialog boxes) continuously untill the user stops. For this we are using TIMERs, but using TIMERs I see there is atleast 10ms delay between the end of first TIMER to the start of next TIMER. We are trying to improve our closed loop frequency and I am not able to reduce this delay?? Is there any other better way rather than using TIMERs, like using threads (but the problem is when I tried using threads before, the interface doesnt respond anymore once the thread has started). thanks in advance.

                  PKNT

                  J Offline
                  J Offline
                  Jeremy Thornton
                  wrote on last edited by
                  #8

                  from MSDN article: How To Use QueryPerformanceCounter to Time Code Function Units Resolution --------------------------------------------------------------------------- Now, Time, Timer seconds 1 second GetTickCount milliseconds approx. 10 ms TimeGetTime milliseconds approx. 10 ms QueryPerformanceCounter QueryPerformanceFrequency same not so much in MFC but Win32 perhaps? your best resolution is probably 10ms NB multicore breaks simple RDTSC approaches you may read about my old article on timing: http://www.codeproject.com/KB/cpp/precision_timer.aspx[^]

                  1 Reply Last reply
                  0
                  • K Kiran Satish

                    Yes.. its true. But I never had much of problems using threads in MFC, they used to work better. But well you can't compare it with other real-time OSes like Linux and other packages that you can get that makes Windows as real-time OS though :) .

                    PKNT

                    J Offline
                    J Offline
                    JudyL_MD
                    wrote on last edited by
                    #9

                    Kiran Satish wrote:

                    other real-time OSes like Linux

                    FYI, Linux is not a RTOS

                    K 1 Reply Last reply
                    0
                    • J JudyL_MD

                      Kiran Satish wrote:

                      other real-time OSes like Linux

                      FYI, Linux is not a RTOS

                      K Offline
                      K Offline
                      Kiran Satish
                      wrote on last edited by
                      #10

                      Yes... I agree, but I am not saying about those commercial Linux Distros (like Fedora, Mandrake etc), there are many RTOSes based on Linux, I meant it in the same way I said about Windows RTOS version packages.

                      PKNT

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups