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. Make Main Thread sleep [modified]

Make Main Thread sleep [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
com
16 Posts 6 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.
  • G GauranG Shah

    Hello Friends, Is there any way we can make the main thread sleep from within the another user created theread. I am using the code like below

    void fun(void)
    {
    ...
    ...

    if(Some Condition)
    {
    CreateThread(0, 0, ( LPTHREAD_START_ROUTINE ) ThreadProc, 0, 0, 0 );
    //I want to show some dialog continuously and also the same function (fun) to be running.
    //And So I am using the Thread to call the Function (fun() )
    DialogBox(...); //
    }
    if (Some Other condition)
    {
    ** //Here I want the main thread to sleep for some time**
    }

    }

    void ThreadProc(void)
    {

    fun();
    

    }

    -- modified at 6:01 Wednesday 17th October, 2007

    [ Screen Capture ][ Tool Tip ]

    C Offline
    C Offline
    chandu004
    wrote on last edited by
    #5

    it seems that, you are landing in some sort of recursion here. BTW, i understood that, you want to do some application, which keeps a dialog displayed until you stop it. am i right? if so, then i can guide you better.

    G 1 Reply Last reply
    0
    • T toxcct

      GauranG33 wrote:

      from within the another user created theread

      WTF are you trying to say here ?! :omg:


      [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

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

      toxcct wrote:

      WTF are you trying to say here ?!

      Don't Know [:)]

      "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
      • G GauranG Shah

        Hello Friends, Is there any way we can make the main thread sleep from within the another user created theread. I am using the code like below

        void fun(void)
        {
        ...
        ...

        if(Some Condition)
        {
        CreateThread(0, 0, ( LPTHREAD_START_ROUTINE ) ThreadProc, 0, 0, 0 );
        //I want to show some dialog continuously and also the same function (fun) to be running.
        //And So I am using the Thread to call the Function (fun() )
        DialogBox(...); //
        }
        if (Some Other condition)
        {
        ** //Here I want the main thread to sleep for some time**
        }

        }

        void ThreadProc(void)
        {

        fun();
        

        }

        -- modified at 6:01 Wednesday 17th October, 2007

        [ Screen Capture ][ Tool Tip ]

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

        Why you want to make Main Thread Sleep..? this is not good design. as in Sleep State main thread will process nothing. you should change you design to make MianThread do nothing instead of making it sleep.

        GauranG33 wrote:

        void ThreadProc(void){ fun();}

        this will make your worker thread sleep not main thread. as function call is from worker thread not main thread

        "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
        • C chandu004

          it seems that, you are landing in some sort of recursion here. BTW, i understood that, you want to do some application, which keeps a dialog displayed until you stop it. am i right? if so, then i can guide you better.

          G Offline
          G Offline
          GauranG Shah
          wrote on last edited by
          #8

          actully I want to display the Dialog Box Continously untill some events happen and also want that my application run in the background and so i am using the thread.

          [ Screen Capture ][ Tool Tip ]

          J C T 3 Replies Last reply
          0
          • G GauranG Shah

            actully I want to display the Dialog Box Continously untill some events happen and also want that my application run in the background and so i am using the thread.

            [ Screen Capture ][ Tool Tip ]

            C Offline
            C Offline
            chandu004
            wrote on last edited by
            #9

            thats what i meant. i have one active X control made by me to achieve your task. if you want, i can share it with u. you have to use it as follows. your main thread { control.start(); //your code which u call as ur background code here ........ ........ //control.stop(); } here, from ur start to stop function, the dialog will be displayed.

            1 Reply Last reply
            0
            • G GauranG Shah

              actully I want to display the Dialog Box Continously untill some events happen and also want that my application run in the background and so i am using the thread.

              [ Screen Capture ][ Tool Tip ]

              J Offline
              J Offline
              JudyL_MD
              wrote on last edited by
              #10

              Have the main thread create and display a modeless dialog box. This way the box is displayed but the main thread can keep working. Judy

              G 1 Reply Last reply
              0
              • G GauranG Shah

                actully I want to display the Dialog Box Continously untill some events happen and also want that my application run in the background and so i am using the thread.

                [ Screen Capture ][ Tool Tip ]

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

                GauranG33 wrote:

                actully I want to display the Dialog Box Continously untill some events happen and also want that my application run in the background and so i am using the thread.

                call a model dialog box.. it block the main thread, and you thread will continue to run in background

                "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
                • J JudyL_MD

                  Have the main thread create and display a modeless dialog box. This way the box is displayed but the main thread can keep working. Judy

                  G Offline
                  G Offline
                  GauranG Shah
                  wrote on last edited by
                  #12

                  yes it displays the modeless dialog

                  [ Screen Capture ][ Tool Tip ]

                  J C T 3 Replies Last reply
                  0
                  • G GauranG Shah

                    yes it displays the modeless dialog

                    [ Screen Capture ][ Tool Tip ]

                    J Offline
                    J Offline
                    JudyL_MD
                    wrote on last edited by
                    #13

                    That wasn't what I meant. I was addressing your statement from the initial post: CreateThread(0, 0, ( LPTHREAD_START_ROUTINE ) ThreadProc, 0, 0, 0 ); //I want to show some dialog continuously and also the same function (fun) to be running. //And So I am using the Thread to call the Function (fun() ) DialogBox(...); // To accomplish this, consider displaying a modeless dialog box and just directly calling the function. This may not be appropriate for your program - it depends on what the function actually does, but you didn't provide enough information. Judy

                    1 Reply Last reply
                    0
                    • G GauranG Shah

                      yes it displays the modeless dialog

                      [ Screen Capture ][ Tool Tip ]

                      C Offline
                      C Offline
                      chandu004
                      wrote on last edited by
                      #14

                      do you exactly want some dialog, that displays something like, "Some task is going on Please Wait......".

                      1 Reply Last reply
                      0
                      • G GauranG Shah

                        Hello Friends, Is there any way we can make the main thread sleep from within the another user created theread. I am using the code like below

                        void fun(void)
                        {
                        ...
                        ...

                        if(Some Condition)
                        {
                        CreateThread(0, 0, ( LPTHREAD_START_ROUTINE ) ThreadProc, 0, 0, 0 );
                        //I want to show some dialog continuously and also the same function (fun) to be running.
                        //And So I am using the Thread to call the Function (fun() )
                        DialogBox(...); //
                        }
                        if (Some Other condition)
                        {
                        ** //Here I want the main thread to sleep for some time**
                        }

                        }

                        void ThreadProc(void)
                        {

                        fun();
                        

                        }

                        -- modified at 6:01 Wednesday 17th October, 2007

                        [ Screen Capture ][ Tool Tip ]

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

                        GauranG33 wrote:

                        //Here I want the main thread to sleep for some time

                        Bad idea.


                        "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                        "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                        1 Reply Last reply
                        0
                        • G GauranG Shah

                          yes it displays the modeless dialog

                          [ Screen Capture ][ Tool Tip ]

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

                          then display model dialog.. is there is any problem..

                          "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
                          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