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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Help with threads.

Help with threads.

Scheduled Pinned Locked Moved C / C++ / MFC
helpalgorithmsquestion
7 Posts 4 Posters 1 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.
  • F Offline
    F Offline
    FISH786
    wrote on last edited by
    #1

    I have been able to get this 3 to work. Window1 and Window2 have 2 different handles to 2 different windows.

    theApp.m_pThreads [0]=AfxBeginThread(Thread,Window1);
    theApp.m_pThreads [1]=AfxBeginThread(Thread,Window2);

    theApp.m_pThreads[0]->ResumeThread();
    theApp.m_pThreads[1]->ResumeThread();

    theApp.m_pThreads[0]->SuspendThread();
    theApp.m_pThreads[1]->SuspendThread();

    My problem is I don't want to create a thread for every window, How do I reuse the threads and change Window1 to Window3. I have tried searching for it, being new I must have missed some articles. Would someone help me with this. Thanks a million.

    C O _ 3 Replies Last reply
    0
    • F FISH786

      I have been able to get this 3 to work. Window1 and Window2 have 2 different handles to 2 different windows.

      theApp.m_pThreads [0]=AfxBeginThread(Thread,Window1);
      theApp.m_pThreads [1]=AfxBeginThread(Thread,Window2);

      theApp.m_pThreads[0]->ResumeThread();
      theApp.m_pThreads[1]->ResumeThread();

      theApp.m_pThreads[0]->SuspendThread();
      theApp.m_pThreads[1]->SuspendThread();

      My problem is I don't want to create a thread for every window, How do I reuse the threads and change Window1 to Window3. I have tried searching for it, being new I must have missed some articles. Would someone help me with this. Thanks a million.

      C Offline
      C Offline
      Chris Losinger
      wrote on last edited by
      #2

      perhaps a Thread Pool[^] would help ?

      image processing toolkits | batch image processing

      F 1 Reply Last reply
      0
      • C Chris Losinger

        perhaps a Thread Pool[^] would help ?

        image processing toolkits | batch image processing

        F Offline
        F Offline
        FISH786
        wrote on last edited by
        #3

        Thank you, I will read on that. I guess i should find Thread pools on code project for samples and better explanation on it. thanks a million.

        C 1 Reply Last reply
        0
        • F FISH786

          Thank you, I will read on that. I guess i should find Thread pools on code project for samples and better explanation on it. thanks a million.

          C Offline
          C Offline
          Chris Losinger
          wrote on last edited by
          #4

          if you can use Boost, there's a threadpool[^] extension which might help, too.

          image processing toolkits | batch image processing

          1 Reply Last reply
          0
          • F FISH786

            I have been able to get this 3 to work. Window1 and Window2 have 2 different handles to 2 different windows.

            theApp.m_pThreads [0]=AfxBeginThread(Thread,Window1);
            theApp.m_pThreads [1]=AfxBeginThread(Thread,Window2);

            theApp.m_pThreads[0]->ResumeThread();
            theApp.m_pThreads[1]->ResumeThread();

            theApp.m_pThreads[0]->SuspendThread();
            theApp.m_pThreads[1]->SuspendThread();

            My problem is I don't want to create a thread for every window, How do I reuse the threads and change Window1 to Window3. I have tried searching for it, being new I must have missed some articles. Would someone help me with this. Thanks a million.

            O Offline
            O Offline
            Ozer Karaagac
            wrote on last edited by
            #5

            Simply. You can consider to pass a pointer to an object instead of Window1. The object that wraps window handle value, should be managable by your main thread.

            class AClassName
            {
            public:
                HWND hWindow;
            };
            
            AClassName* pACN new AClassName;
            pACN->hWindow = Window1;
            
            theApp.m_pThreads [0] = AfxBeginThread(Thread, pACN);
            

            Then you can refer to pACN->hWindow in your thread function appropriately. You may have to employ some synchronization technics, too.

            1 Reply Last reply
            0
            • F FISH786

              I have been able to get this 3 to work. Window1 and Window2 have 2 different handles to 2 different windows.

              theApp.m_pThreads [0]=AfxBeginThread(Thread,Window1);
              theApp.m_pThreads [1]=AfxBeginThread(Thread,Window2);

              theApp.m_pThreads[0]->ResumeThread();
              theApp.m_pThreads[1]->ResumeThread();

              theApp.m_pThreads[0]->SuspendThread();
              theApp.m_pThreads[1]->SuspendThread();

              My problem is I don't want to create a thread for every window, How do I reuse the threads and change Window1 to Window3. I have tried searching for it, being new I must have missed some articles. Would someone help me with this. Thanks a million.

              _ Offline
              _ Offline
              _Superman_
              wrote on last edited by
              #6

              You can use PostThreadMessage to pass in the window handle to the thread to switch from one window to another. And never pass the window object from one thread to another. Always pass the window handle and attach it to a new window object using CWnd::FromHandle inside the thread. A window handle and its object is managed by MFC using a map which is valid only for the current thread.

              «_Superman_» I love work. It gives me something to do between weekends.

              F 1 Reply Last reply
              0
              • _ _Superman_

                You can use PostThreadMessage to pass in the window handle to the thread to switch from one window to another. And never pass the window object from one thread to another. Always pass the window handle and attach it to a new window object using CWnd::FromHandle inside the thread. A window handle and its object is managed by MFC using a map which is valid only for the current thread.

                «_Superman_» I love work. It gives me something to do between weekends.

                F Offline
                F Offline
                FISH786
                wrote on last edited by
                #7

                It seems that will be my best choice for now. I can't find any articles or demo's on a thread pool using vc++. All I have seen so far are in C#.

                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