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. I want to run Thread at regular interval using multimedia timer [modified]

I want to run Thread at regular interval using multimedia timer [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
help
2 Posts 2 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.
  • A Offline
    A Offline
    anilaabc
    wrote on last edited by
    #1

    I want to do two to three tasks at the same time at regular interval ,time is important so i m using multimedia timer . problem is ....timer run the thread only once .code is below when I click button thread is created and multimedia timer is set. count is an integer initialized with 0 void CTimerDlg::Onbtnstart() { Thread=AfxBeginThread(ThreadDisplay, this, THREAD_PRIORITY_TIME_CRITICAL,0 ,CREATE_SUSPENDED); handle=Thread->m_hThread; Thread->m_bAutoDelete=false; timeSetEvent(100, 0, TimeProcVideo, (DWORD)this, TIME_PERIODIC); } //thread analyzing data UINT ThreadDisplay(LPVOID lParam) { CTimerDlg *obj=(CTimerDlg*) lParam; obj->abc(); return 1; } void CTimerDlg::abc() { count++; char a[20]; GetDlgItem(IDC_STATIC)->SetWindowText(""); CString s=itoa(count,a,10); GetDlgItem(IDC_STATIC)->SetWindowText(s); SuspendThread(handle); } void CALLBACK TimeProcVideo(UINT uID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2) { CTimerDlg* timer=(CTimerDlg*) dwUser; timer->ControlThreads(); } void CTimerDlg::ControlThreads() { ResumeThread(handle); }

    modified on Friday, November 28, 2008 11:18 PM

    R 1 Reply Last reply
    0
    • A anilaabc

      I want to do two to three tasks at the same time at regular interval ,time is important so i m using multimedia timer . problem is ....timer run the thread only once .code is below when I click button thread is created and multimedia timer is set. count is an integer initialized with 0 void CTimerDlg::Onbtnstart() { Thread=AfxBeginThread(ThreadDisplay, this, THREAD_PRIORITY_TIME_CRITICAL,0 ,CREATE_SUSPENDED); handle=Thread->m_hThread; Thread->m_bAutoDelete=false; timeSetEvent(100, 0, TimeProcVideo, (DWORD)this, TIME_PERIODIC); } //thread analyzing data UINT ThreadDisplay(LPVOID lParam) { CTimerDlg *obj=(CTimerDlg*) lParam; obj->abc(); return 1; } void CTimerDlg::abc() { count++; char a[20]; GetDlgItem(IDC_STATIC)->SetWindowText(""); CString s=itoa(count,a,10); GetDlgItem(IDC_STATIC)->SetWindowText(s); SuspendThread(handle); } void CALLBACK TimeProcVideo(UINT uID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2) { CTimerDlg* timer=(CTimerDlg*) dwUser; timer->ControlThreads(); } void CTimerDlg::ControlThreads() { ResumeThread(handle); }

      modified on Friday, November 28, 2008 11:18 PM

      R Offline
      R Offline
      Roger Stoltz
      wrote on last edited by
      #2

      :confused: :omg: :confused: What on earth are you trying to do? I mean that question very sincerely because you seem to have misunderstood the concept of multithreading completely. If you experience the thread to run at least once, you must be calling ::ResumeThread() from some code that you have not provided in this post, which suggests that there may be more to it than the code you've posted. What the code you provided does is create a thread suspended. When the thread resumes execution it will call the abc() function. In the same call chain ::SuspendThread() will be called and when ::ResumeThread() is called in order to let the thread resume execution, the thread will simply exit. That's why the "thread only runs once". For the rest of us to be able to help you as constructive as possible, please answer this: Why do you think you need multiple threads?

      "It's supposed to be hard, otherwise anybody could do it!" - selfquote
      "High speed never compensates for wrong direction!" - unknown

      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