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. how to create new thread

how to create new thread

Scheduled Pinned Locked Moved C / C++ / MFC
c++designhelptutorial
18 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.
  • H hemlat

    Hi, I need to create new thread if I click on particular button in my MFC application.I have added following code.

    AfxBeginThread( CRuntimeClass* pfnThreadProc,LPVOID pParam,
    int nPriority = THREAD_PRIORITY_NORMAL,UINT nStackSize = 0,
    DWORD dwCreateFlags = 0,LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL);
    UINT CTestcycleDlg::pfnThreadProc(LPVOID pParam )
    {
    }

    I am getting errors one of thoes error is error C2275: 'CRuntimeClass' : illegal use of this type as an expression I have created user interface thread.Is it correct.Where I need to close thread and how to close

    D Offline
    D Offline
    David Crow
    wrote on last edited by
    #9

    hemlat wrote:

    AfxBeginThread( CRuntimeClass* pfnThreadProc,LPVOID pParam, int nPriority = THREAD_PRIORITY_NORMAL,UINT nStackSize = 0, DWORD dwCreateFlags = 0,LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL);

    What is this? Are you trying to call AfxBeginThread(), or just duplicate the prototype?

    "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

    "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

    H 1 Reply Last reply
    0
    • H hemlat

      Hi, I need to create new thread if I click on particular button in my MFC application.I have added following code.

      AfxBeginThread( CRuntimeClass* pfnThreadProc,LPVOID pParam,
      int nPriority = THREAD_PRIORITY_NORMAL,UINT nStackSize = 0,
      DWORD dwCreateFlags = 0,LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL);
      UINT CTestcycleDlg::pfnThreadProc(LPVOID pParam )
      {
      }

      I am getting errors one of thoes error is error C2275: 'CRuntimeClass' : illegal use of this type as an expression I have created user interface thread.Is it correct.Where I need to close thread and how to close

      T Offline
      T Offline
      ThatsAlok
      wrote on last edited by
      #10

      hemlat wrote:

      UINT CTestcycleDlg::pfnThreadProc(LPVOID pParam )

      i think you forget to make function static

      "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
      Never mind - my own stupidity is the source of every "problem" - Mixture

      cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You

      1 Reply Last reply
      0
      • R Rajesh R Subramanian

        Divyang Mithaiwala wrote:

        You can use createThread method.There is no matter of MFC.

        Actually, there is. Please read the docs[^]

        It is a crappy thing, but it's life -^ Carlo Pallini

        T Offline
        T Offline
        ThatsAlok
        wrote on last edited by
        #11

        Rajesh R Subramanian wrote:

        Actually, there is. Please read the docs[^]

        Good reference

        "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
        Never mind - my own stupidity is the source of every "problem" - Mixture

        cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You

        1 Reply Last reply
        0
        • D David Crow

          hemlat wrote:

          AfxBeginThread( CRuntimeClass* pfnThreadProc,LPVOID pParam, int nPriority = THREAD_PRIORITY_NORMAL,UINT nStackSize = 0, DWORD dwCreateFlags = 0,LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL);

          What is this? Are you trying to call AfxBeginThread(), or just duplicate the prototype?

          "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          H Offline
          H Offline
          hemlat
          wrote on last edited by
          #12

          Actually I dont know how to create thread.I have tried with above code.I am seaching the code for thread creation.

          R 1 Reply Last reply
          0
          • H hemlat

            Actually I dont know how to create thread.I have tried with above code.I am seaching the code for thread creation.

            R Offline
            R Offline
            Rajesh R Subramanian
            wrote on last edited by
            #13

            hemlat wrote:

            I am seaching the code for thread creation. Quote Selected Text

            Still?! Are you kidding me? I gave you link to an excellent UI thread tutorial yesterday. Did you read it or not? Why are you "searching" for code, BTW? You're supposed to write code if you are a programmer of any kind.

            It is a crappy thing, but it's life -^ Carlo Pallini

            H 1 Reply Last reply
            0
            • R Rajesh R Subramanian

              hemlat wrote:

              I am seaching the code for thread creation. Quote Selected Text

              Still?! Are you kidding me? I gave you link to an excellent UI thread tutorial yesterday. Did you read it or not? Why are you "searching" for code, BTW? You're supposed to write code if you are a programmer of any kind.

              It is a crappy thing, but it's life -^ Carlo Pallini

              H Offline
              H Offline
              hemlat
              wrote on last edited by
              #14

              Thanks for your reply.Just now I have started working.Morning I was busy with some other task.Just I replyed to his message he was asking me what I was doing.I started working on Link which u hv sent.

              H 1 Reply Last reply
              0
              • H hemlat

                Thanks for your reply.Just now I have started working.Morning I was busy with some other task.Just I replyed to his message he was asking me what I was doing.I started working on Link which u hv sent.

                H Offline
                H Offline
                hemlat
                wrote on last edited by
                #15

                I need to create worker thread.Because I need to put my functionality in thread function. Can you suggest any link which will show how to create worker thread

                R D 2 Replies Last reply
                0
                • H hemlat

                  I need to create worker thread.Because I need to put my functionality in thread function. Can you suggest any link which will show how to create worker thread

                  R Offline
                  R Offline
                  Rajesh R Subramanian
                  wrote on last edited by
                  #16

                  Bookmark the MVP Tips[^] page. There's plenty of good essays there. Look for "Using Worker Threads" essay for your purpose.

                  It is a crappy thing, but it's life -^ Carlo Pallini

                  H 1 Reply Last reply
                  0
                  • H hemlat

                    I need to create worker thread.Because I need to put my functionality in thread function. Can you suggest any link which will show how to create worker thread

                    D Offline
                    D Offline
                    David Crow
                    wrote on last edited by
                    #17

                    hemlat wrote:

                    Can you suggest any link which will show how to create worker thread

                    Did you even bother to read the article that Rajesh provided? If you had, you would have noticied a link to this. :rolleyes:

                    "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                    "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                    1 Reply Last reply
                    0
                    • R Rajesh R Subramanian

                      Bookmark the MVP Tips[^] page. There's plenty of good essays there. Look for "Using Worker Threads" essay for your purpose.

                      It is a crappy thing, but it's life -^ Carlo Pallini

                      H Offline
                      H Offline
                      hemlat
                      wrote on last edited by
                      #18

                      thanks for your reply.I have created thread.I got article in Codeproject.Sorry for late reply.

                      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