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. worker thread did not survive the release version - MFC

worker thread did not survive the release version - MFC

Scheduled Pinned Locked Moved C / C++ / MFC
announcementc++debuggingtools
4 Posts 4 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
    awah
    wrote on last edited by
    #1

    worker thread did not survive the release version - MFC in the debug version it did not clash and ran smooth, and completed the cyclesequence function but it clashed badly in the release version. cyclesequence function was never completed sry i am very bad in threading. i have search all over but cannot find the solution ok here's how my program goes when the user presses a button called "RUN" , i begin my thread void COpc_serialDlg::OnRun() { m_th_sequence = AfxBeginThread(th_start_sequence, (LPVOID)this ); m_run.EnableWindow(FALSE); } my thread begins by obtaining information from editboxes and starts a function called CycleSequence UINT COpc_serialDlg::th_start_sequence(LPVOID lpvParam) { COpc_serialDlg *th_start_receiving = (COpc_serialDlg*)lpvParam; // standard in thread int times = 0; CString startstring = ""; CString repeatstring = ""; CString endstring = ""; times = th_start_receiving->GetDlgItemInt(IDC_REPEAT_TIMES1); th_start_receiving->GetDlgItemText(IDC_STARTKEY1 , *startstring); th_start_receiving->GetDlgItemText(IDC_REPEAT1 , *repeatstring); th_start_receiving->GetDlgItemText(IDC_ENDKEY1 , *endstring); th_start_receiving->CycleSequence(times, *startstring, *repeatstring, *endstring); th_start_receiving->PrintRedDebugMsg( "Cycle thread exiting"); th_start_receiving->m_run.EnableWindow(TRUE); return 0; } here's how CycleSequence function looks like int COpc_serialDlg::CycleSequence(int times, CString startstring, CString repeatstring, CString endstring) { CString temp_string = ""; int i = 0; int Stroke_Count = GetNumberOfStrokes( startstring); CString local_repeatstring = ""; CString local_repeatstring2 = ""; // SetTimer(999 , 2000,0); // only when this timer expires, green light will come again, if red light is set again, timer resets // start string just write once before anything else for( i = 0 ; i < Stroke_Count ; i++) { local_repeatstring = startstring; m_serial.Write(Read_Out_Int(local_repeatstring),1,0,0,10); // 5000 ms timeout startstring = Remove_Out_Int(startstring); // let's wait 15 seconds for a response from OPC SetTimer( 999 , 15000 , NULL); WaitForSingleObject(m_idle_event , INFINITE); // after every .write command must contain this } // looping script is here Stroke_Count = GetNumberOfStrokes( repeatstring); for( i = 0 ; i < times ; i++) { local_repeatstring = repeatstring; for( int j = 0 ; j < Stroke_

    X P R 3 Replies Last reply
    0
    • A awah

      worker thread did not survive the release version - MFC in the debug version it did not clash and ran smooth, and completed the cyclesequence function but it clashed badly in the release version. cyclesequence function was never completed sry i am very bad in threading. i have search all over but cannot find the solution ok here's how my program goes when the user presses a button called "RUN" , i begin my thread void COpc_serialDlg::OnRun() { m_th_sequence = AfxBeginThread(th_start_sequence, (LPVOID)this ); m_run.EnableWindow(FALSE); } my thread begins by obtaining information from editboxes and starts a function called CycleSequence UINT COpc_serialDlg::th_start_sequence(LPVOID lpvParam) { COpc_serialDlg *th_start_receiving = (COpc_serialDlg*)lpvParam; // standard in thread int times = 0; CString startstring = ""; CString repeatstring = ""; CString endstring = ""; times = th_start_receiving->GetDlgItemInt(IDC_REPEAT_TIMES1); th_start_receiving->GetDlgItemText(IDC_STARTKEY1 , *startstring); th_start_receiving->GetDlgItemText(IDC_REPEAT1 , *repeatstring); th_start_receiving->GetDlgItemText(IDC_ENDKEY1 , *endstring); th_start_receiving->CycleSequence(times, *startstring, *repeatstring, *endstring); th_start_receiving->PrintRedDebugMsg( "Cycle thread exiting"); th_start_receiving->m_run.EnableWindow(TRUE); return 0; } here's how CycleSequence function looks like int COpc_serialDlg::CycleSequence(int times, CString startstring, CString repeatstring, CString endstring) { CString temp_string = ""; int i = 0; int Stroke_Count = GetNumberOfStrokes( startstring); CString local_repeatstring = ""; CString local_repeatstring2 = ""; // SetTimer(999 , 2000,0); // only when this timer expires, green light will come again, if red light is set again, timer resets // start string just write once before anything else for( i = 0 ; i < Stroke_Count ; i++) { local_repeatstring = startstring; m_serial.Write(Read_Out_Int(local_repeatstring),1,0,0,10); // 5000 ms timeout startstring = Remove_Out_Int(startstring); // let's wait 15 seconds for a response from OPC SetTimer( 999 , 15000 , NULL); WaitForSingleObject(m_idle_event , INFINITE); // after every .write command must contain this } // looping script is here Stroke_Count = GetNumberOfStrokes( repeatstring); for( i = 0 ; i < times ; i++) { local_repeatstring = repeatstring; for( int j = 0 ; j < Stroke_

      X Offline
      X Offline
      Xing Chen
      wrote on last edited by
      #2

      Function UINT COpc_serialDlg::th_start_sequence(LPVOID lpvParam) must be static

      1 Reply Last reply
      0
      • A awah

        worker thread did not survive the release version - MFC in the debug version it did not clash and ran smooth, and completed the cyclesequence function but it clashed badly in the release version. cyclesequence function was never completed sry i am very bad in threading. i have search all over but cannot find the solution ok here's how my program goes when the user presses a button called "RUN" , i begin my thread void COpc_serialDlg::OnRun() { m_th_sequence = AfxBeginThread(th_start_sequence, (LPVOID)this ); m_run.EnableWindow(FALSE); } my thread begins by obtaining information from editboxes and starts a function called CycleSequence UINT COpc_serialDlg::th_start_sequence(LPVOID lpvParam) { COpc_serialDlg *th_start_receiving = (COpc_serialDlg*)lpvParam; // standard in thread int times = 0; CString startstring = ""; CString repeatstring = ""; CString endstring = ""; times = th_start_receiving->GetDlgItemInt(IDC_REPEAT_TIMES1); th_start_receiving->GetDlgItemText(IDC_STARTKEY1 , *startstring); th_start_receiving->GetDlgItemText(IDC_REPEAT1 , *repeatstring); th_start_receiving->GetDlgItemText(IDC_ENDKEY1 , *endstring); th_start_receiving->CycleSequence(times, *startstring, *repeatstring, *endstring); th_start_receiving->PrintRedDebugMsg( "Cycle thread exiting"); th_start_receiving->m_run.EnableWindow(TRUE); return 0; } here's how CycleSequence function looks like int COpc_serialDlg::CycleSequence(int times, CString startstring, CString repeatstring, CString endstring) { CString temp_string = ""; int i = 0; int Stroke_Count = GetNumberOfStrokes( startstring); CString local_repeatstring = ""; CString local_repeatstring2 = ""; // SetTimer(999 , 2000,0); // only when this timer expires, green light will come again, if red light is set again, timer resets // start string just write once before anything else for( i = 0 ; i < Stroke_Count ; i++) { local_repeatstring = startstring; m_serial.Write(Read_Out_Int(local_repeatstring),1,0,0,10); // 5000 ms timeout startstring = Remove_Out_Int(startstring); // let's wait 15 seconds for a response from OPC SetTimer( 999 , 15000 , NULL); WaitForSingleObject(m_idle_event , INFINITE); // after every .write command must contain this } // looping script is here Stroke_Count = GetNumberOfStrokes( repeatstring); for( i = 0 ; i < times ; i++) { local_repeatstring = repeatstring; for( int j = 0 ; j < Stroke_

        P Offline
        P Offline
        prasad_som
        wrote on last edited by
        #3

        awah wrote:

        there are also other functions in CycleSequence like m_serial.Write , Remove_Out_Int and Read_Out_Int and GetNumberOfStrokes i did not include them here because i dont think they are causing the problem.

        Not necessary. Its very difficult from seeing this code, to find out the problem. You can put down message boxes in code and narrow down the rpblem code. Additionally , refer this article by Joseph M. NewComer Joseph M. NewComer[^].

        Prasad Notifier using ATL | Operator new[],delete[][^]

        1 Reply Last reply
        0
        • A awah

          worker thread did not survive the release version - MFC in the debug version it did not clash and ran smooth, and completed the cyclesequence function but it clashed badly in the release version. cyclesequence function was never completed sry i am very bad in threading. i have search all over but cannot find the solution ok here's how my program goes when the user presses a button called "RUN" , i begin my thread void COpc_serialDlg::OnRun() { m_th_sequence = AfxBeginThread(th_start_sequence, (LPVOID)this ); m_run.EnableWindow(FALSE); } my thread begins by obtaining information from editboxes and starts a function called CycleSequence UINT COpc_serialDlg::th_start_sequence(LPVOID lpvParam) { COpc_serialDlg *th_start_receiving = (COpc_serialDlg*)lpvParam; // standard in thread int times = 0; CString startstring = ""; CString repeatstring = ""; CString endstring = ""; times = th_start_receiving->GetDlgItemInt(IDC_REPEAT_TIMES1); th_start_receiving->GetDlgItemText(IDC_STARTKEY1 , *startstring); th_start_receiving->GetDlgItemText(IDC_REPEAT1 , *repeatstring); th_start_receiving->GetDlgItemText(IDC_ENDKEY1 , *endstring); th_start_receiving->CycleSequence(times, *startstring, *repeatstring, *endstring); th_start_receiving->PrintRedDebugMsg( "Cycle thread exiting"); th_start_receiving->m_run.EnableWindow(TRUE); return 0; } here's how CycleSequence function looks like int COpc_serialDlg::CycleSequence(int times, CString startstring, CString repeatstring, CString endstring) { CString temp_string = ""; int i = 0; int Stroke_Count = GetNumberOfStrokes( startstring); CString local_repeatstring = ""; CString local_repeatstring2 = ""; // SetTimer(999 , 2000,0); // only when this timer expires, green light will come again, if red light is set again, timer resets // start string just write once before anything else for( i = 0 ; i < Stroke_Count ; i++) { local_repeatstring = startstring; m_serial.Write(Read_Out_Int(local_repeatstring),1,0,0,10); // 5000 ms timeout startstring = Remove_Out_Int(startstring); // let's wait 15 seconds for a response from OPC SetTimer( 999 , 15000 , NULL); WaitForSingleObject(m_idle_event , INFINITE); // after every .write command must contain this } // looping script is here Stroke_Count = GetNumberOfStrokes( repeatstring); for( i = 0 ; i < times ; i++) { local_repeatstring = repeatstring; for( int j = 0 ; j < Stroke_

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

          awah wrote:

          my thread begins by obtaining information from editboxes

          Well, this is a definite no-no from worker threads. Never touch the GUI from a worker thread, it may cause a deadlock. Read Joe Newcomer's article on the subject to get a better understanding of how to do worker threads here[^].


          "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