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#
  4. how do i make a program wait indefinitely

how do i make a program wait indefinitely

Scheduled Pinned Locked Moved C#
question
11 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.
  • V Vivek Vijayan

    i m doing an networked application.how do i make a program wait indefinitely until an input is received...like getche() or getch() in c

    This code was posted by me...

    U Offline
    U Offline
    Uri Lavi
    wrote on last edited by
    #2

    The best way is to wait on AutoResetEvent or ManualResetEvent and once the input is constructed, to signal those events

    Uri

    V 1 Reply Last reply
    0
    • U Uri Lavi

      The best way is to wait on AutoResetEvent or ManualResetEvent and once the input is constructed, to signal those events

      Uri

      V Offline
      V Offline
      Vivek Vijayan
      wrote on last edited by
      #3

      cant we do without using thread???

      This code was posted by me...

      U 1 Reply Last reply
      0
      • V Vivek Vijayan

        cant we do without using thread???

        This code was posted by me...

        U Offline
        U Offline
        Uri Lavi
        wrote on last edited by
        #4

        It seems to me that your desired result is to be interrupted once the input is received. Interruption by definition means context-switching (threads). You can apply a different approach (which is not a good design), by checking a boolean variable in a while loop. As stated this isn't desired as: 1. You will waste the cpu cycles 2. You will have threads anyway 3. You will need to deal with the race condition by applying locks - as one thread will read the boolean whereas another thread will write.

        Uri

        L 1 Reply Last reply
        0
        • V Vivek Vijayan

          i m doing an networked application.how do i make a program wait indefinitely until an input is received...like getche() or getch() in c

          This code was posted by me...

          B Offline
          B Offline
          Baeltazor
          wrote on last edited by
          #5

          I always thought it was cin << ReadKey(); ...Or has my memory gone KABOOM! again?

          R 1 Reply Last reply
          0
          • B Baeltazor

            I always thought it was cin << ReadKey(); ...Or has my memory gone KABOOM! again?

            R Offline
            R Offline
            riced
            wrote on last edited by
            #6

            That's C++. :-D

            Regards David R --------------------------------------------------------------- "Every program eventually becomes rococo, and then rubble." - Alan Perlis

            1 Reply Last reply
            0
            • V Vivek Vijayan

              i m doing an networked application.how do i make a program wait indefinitely until an input is received...like getche() or getch() in c

              This code was posted by me...

              P Offline
              P Offline
              PIEBALDconsult
              wrote on last edited by
              #7

              Are you sure you don't want a Windows Service?

              1 Reply Last reply
              0
              • U Uri Lavi

                It seems to me that your desired result is to be interrupted once the input is received. Interruption by definition means context-switching (threads). You can apply a different approach (which is not a good design), by checking a boolean variable in a while loop. As stated this isn't desired as: 1. You will waste the cpu cycles 2. You will have threads anyway 3. You will need to deal with the race condition by applying locks - as one thread will read the boolean whereas another thread will write.

                Uri

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #8

                You don't need a lock for a bool though, just make it volatile and be careful when reading it (copy to local first)

                1 Reply Last reply
                0
                • V Vivek Vijayan

                  i m doing an networked application.how do i make a program wait indefinitely until an input is received...like getche() or getch() in c

                  This code was posted by me...

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #9

                  Input from what, the network? If so, just do a blocking read without timeout?

                  V 1 Reply Last reply
                  0
                  • L Lost User

                    Input from what, the network? If so, just do a blocking read without timeout?

                    V Offline
                    V Offline
                    Vivek Vijayan
                    wrote on last edited by
                    #10

                    yes from network how do i block read??

                    This code was posted by me...

                    L 1 Reply Last reply
                    0
                    • V Vivek Vijayan

                      yes from network how do i block read??

                      This code was posted by me...

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #11

                      If you make a NetworkStream, a normal Read should be blocking - I think. But don't trust me on this one, go to MSDN and check..

                      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