Function that never returns
-
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!
-
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!
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
-
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!
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.
-
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
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.
-
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.
So, throw a
Thread.Sleep(10)
in thewhile
loop.Dave Kreskowiak Microsoft MVP - Visual Basic
-
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!
-
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.
-
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.
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
-
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