CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2003
    Location
    Malaysia
    Posts
    57

    Question How to use Ctime?

    Hello,
    How are you all? A question, or more like a problem has crept up in my programming as of late. I tried to solve it by myself, but to no avail. It concerns CTime.

    There's a part of my program where I require it to execute a certain operation every 100ms, but so far, I could only make a stopwatch type timer. Is there a way where every 100ms, a whole set of subroutine will run?

    I ask this becouse I am currently writing a simulation program and I have in mind discrete events happening every 100ms in my simulation.

    Please help.

    -Andy

  2. #2
    Join Date
    Jan 2004
    Posts
    206
    I believe what u need is not CTime class. You need a Timer. Check out SetTimer and KillTimer in MSDN.

  3. #3
    Join Date
    Aug 2003
    Location
    Malaysia
    Posts
    57
    I did that, and i used that. this this the code fragment that i use.
    Code:
    void ???::OnTimer(UINT nIDEvent)
    {...
     switch (nIDEvent)
      {
      case ID_CLOCK_TIMER
      break;
      case ID_COUNT_TIMER
      //**
      //the only place (that i know of) that executes once every 100ms
      m_iCount++;
      break;
      }
    UpdateData(FALSE);
    ...
    }
    ...
    void ???::OnSimulate()
    {
    //*
    m_iCount=0;
    SetTimer(ID_COUNT_TIMER, 100, NULL)
    }
    is there a way where i can circumvent this method? I meant that the only way i can make sure something happens every 100ms is to put my codes at ** instead of at *. Now, for short codes I wouldn't mind, but the bulk(hundreds of lines) of my codes depend upon it executing every 100ms. is there anyway that i could put my codes in * and still it executes every 100ms??

  4. #4
    Join Date
    Apr 2003
    Location
    UK
    Posts
    83
    The WM_TIMER message is not accurate for what you require; they are processed at low priority, and are often delayed whilst other higher priority messages are processed. I think what you need is MSHTML Timer - look it up in MSDN.

  5. #5
    Join Date
    Aug 2003
    Location
    Malaysia
    Posts
    57
    thank you astanley for your reply. I searched MSDN and I never found the MSHTML Timer you told me. but I did found something about worker thread. But the method described there is a little too crude for my purposes.

    now, I believe I have solved my little hiccup; I call the class that I want from the OnTimer class. so far, it works.

    just out of curiousity, how do you guys do a simulation software that 'refreshes' the window every few seconds? i mean re-evaluate the variables, re-roll the dice so to speak.

  6. #6
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656
    Originally posted by astanley
    The WM_TIMER message [...] processed at low priority, and are often delayed whilst other higher priority messages are processed.
    "low priority" and "higher priority" messages??? On Windows?
    I always thought there is ONE message queue...
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured