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. Function that never returns

Function that never returns

Scheduled Pinned Locked Moved C#
csharpdotnetquestion
10 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 Offline
    V Offline
    Vega02
    wrote on last edited by
    #1

    Just out of sick curiosity, is there a function in the .NET Framework that I can call that is guaranteed to block forever? Right now I'm creating a new ManualResetEvent object, then calling its WaitOne() method. The reason for this is that I'm calling a ton of Stream.BeginRead() methods from my Main() method, and the delegates called when these reads complete eventually take over program execution. I'm pretty sure that this is bad coding style, but this is just for an experimental application, not a production app. :) Thanks!

    E P G 3 Replies Last reply
    0
    • V Vega02

      Just out of sick curiosity, is there a function in the .NET Framework that I can call that is guaranteed to block forever? Right now I'm creating a new ManualResetEvent object, then calling its WaitOne() method. The reason for this is that I'm calling a ton of Stream.BeginRead() methods from my Main() method, and the delegates called when these reads complete eventually take over program execution. I'm pretty sure that this is bad coding style, but this is just for an experimental application, not a production app. :) Thanks!

      E Offline
      E Offline
      Ed Poore
      wrote on last edited by
      #2

      public void NeverExit()
      {
       while (true)
        ;
      }

      ? What was so difficult?


      Formula 1 - Short for "F1 Racing" - named after the standard "help" key in Windows, it's a sport where participants desperately search through software help files trying to find actual documentation. It's tedious and somewhat cruel, most matches ending in a draw as no participant is able to find anything helpful. - Shog9 Ed

      V 1 Reply Last reply
      0
      • V Vega02

        Just out of sick curiosity, is there a function in the .NET Framework that I can call that is guaranteed to block forever? Right now I'm creating a new ManualResetEvent object, then calling its WaitOne() method. The reason for this is that I'm calling a ton of Stream.BeginRead() methods from my Main() method, and the delegates called when these reads complete eventually take over program execution. I'm pretty sure that this is bad coding style, but this is just for an experimental application, not a production app. :) Thanks!

        P Offline
        P Offline
        Pete OHanlon
        wrote on last edited by
        #3
        while (1 == 1)
        {
        // Do something....
        }
        

        Arthur Dent - "That would explain it. All my life I've had this strange feeling that there's something big and sinister going on in the world." Slartibartfast - "No. That's perfectly normal paranoia. Everybody in the universe gets that." Deja View - the feeling that you've seen this post before.

        1 Reply Last reply
        0
        • E Ed Poore

          public void NeverExit()
          {
           while (true)
            ;
          }

          ? What was so difficult?


          Formula 1 - Short for "F1 Racing" - named after the standard "help" key in Windows, it's a sport where participants desperately search through software help files trying to find actual documentation. It's tedious and somewhat cruel, most matches ending in a draw as no participant is able to find anything helpful. - Shog9 Ed

          V Offline
          V Offline
          Vega02
          wrote on last edited by
          #4

          Well, yeah - but I was hoping for something that didn't burn clock cycles like mad. My program *does* have other threads doing real work, after all. :) Like I said, this is strictly an academic exercise for my own sake. If indefinitely suspending the Main() thread is the wrong way of going about this, I'm certainly open to alternatives. BTW, I also thought of using Thread.Suspend(), but unfortunately it has been deprecated.

          D L E 3 Replies Last reply
          0
          • V Vega02

            Well, yeah - but I was hoping for something that didn't burn clock cycles like mad. My program *does* have other threads doing real work, after all. :) Like I said, this is strictly an academic exercise for my own sake. If indefinitely suspending the Main() thread is the wrong way of going about this, I'm certainly open to alternatives. BTW, I also thought of using Thread.Suspend(), but unfortunately it has been deprecated.

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #5

            So, throw a Thread.Sleep(10) in the while loop.

            Dave Kreskowiak Microsoft MVP - Visual Basic

            1 Reply Last reply
            0
            • V Vega02

              Just out of sick curiosity, is there a function in the .NET Framework that I can call that is guaranteed to block forever? Right now I'm creating a new ManualResetEvent object, then calling its WaitOne() method. The reason for this is that I'm calling a ton of Stream.BeginRead() methods from my Main() method, and the delegates called when these reads complete eventually take over program execution. I'm pretty sure that this is bad coding style, but this is just for an experimental application, not a production app. :) Thanks!

              G Offline
              G Offline
              Guffa
              wrote on last edited by
              #6

              Thread.Sleep(Infinite);

              --- b { font-weight: normal; }

              V 1 Reply Last reply
              0
              • G Guffa

                Thread.Sleep(Infinite);

                --- b { font-weight: normal; }

                V Offline
                V Offline
                Vega02
                wrote on last edited by
                #7

                Of course! I had completely forgotten about that. Thanks :)

                1 Reply Last reply
                0
                • V Vega02

                  Well, yeah - but I was hoping for something that didn't burn clock cycles like mad. My program *does* have other threads doing real work, after all. :) Like I said, this is strictly an academic exercise for my own sake. If indefinitely suspending the Main() thread is the wrong way of going about this, I'm certainly open to alternatives. BTW, I also thought of using Thread.Suspend(), but unfortunately it has been deprecated.

                  L Offline
                  L Offline
                  led mike
                  wrote on last edited by
                  #8

                  Vega02 wrote:

                  If indefinitely suspending the Main() thread is the wrong way of going about this, I'm certainly open to alternatives.

                  You mean like blocking on an Event until another thread signals it? :rolleyes:

                  led mike

                  V 1 Reply Last reply
                  0
                  • V Vega02

                    Well, yeah - but I was hoping for something that didn't burn clock cycles like mad. My program *does* have other threads doing real work, after all. :) Like I said, this is strictly an academic exercise for my own sake. If indefinitely suspending the Main() thread is the wrong way of going about this, I'm certainly open to alternatives. BTW, I also thought of using Thread.Suspend(), but unfortunately it has been deprecated.

                    E Offline
                    E Offline
                    Ed Poore
                    wrote on last edited by
                    #9

                    As mentioned below Thread.Sleep(Timeout.Infinite) is what you want.


                    Formula 1 - Short for "F1 Racing" - named after the standard "help" key in Windows, it's a sport where participants desperately search through software help files trying to find actual documentation. It's tedious and somewhat cruel, most matches ending in a draw as no participant is able to find anything helpful. - Shog9 Ed

                    1 Reply Last reply
                    0
                    • L led mike

                      Vega02 wrote:

                      If indefinitely suspending the Main() thread is the wrong way of going about this, I'm certainly open to alternatives.

                      You mean like blocking on an Event until another thread signals it? :rolleyes:

                      led mike

                      V Offline
                      V Offline
                      Vega02
                      wrote on last edited by
                      #10

                      Well, yeah, but in my case no other thread will ever signal it. Creating a ManualResetEvent and waiting on it to perform an indefinite block - something just feels wrong about doing that. ;P

                      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