you always want to prevent using while loops, especially when you are forcing the code to recheck variables. It wastes CPU resources and slows down your program.
I would definitely say the first one.
More Related Contents:
- Why is Thread.Sleep so harmful
- Compare using Thread.Sleep and Timer for delayed execution
- How accurate is Thread.Sleep(TimeSpan)?
- What is the difference between ManualResetEvent and AutoResetEvent in .NET?
- Automating the InvokeRequired code pattern
- How do I abort/cancel TPL Tasks?
- Cross-thread operation not valid [duplicate]
- Concurrent HashSet in .NET Framework?
- Can a C# thread really cache a value and ignore changes to that value on other threads?
- BackgroundWorker RunWorkerCompleted Event
- How do I run a simple bit of code in a new thread?
- C# Thread Termination and Thread.Abort()
- How to protect resources that may be used in a multi-threaded or async environment?
- Cancelling a pending task synchronously on the UI thread
- Set timeout to an operation
- What is a thread exit code?
- Does using Tasks (TPL) library make an application multithreaded?
- lock keyword in C#
- Wait for a while without blocking main thread
- Workaround for the WaitHandle.WaitAll 64 handle limit?
- Progress Bar not available for zipfile? How to give feedback when program seems to hang
- How to interrupt Console.ReadLine
- How to exit all running threads?
- Access to disposed closure in C#?
- Return a value from an Event — is there a Good Practice for this?
- Does Func.BeginInvoke use the ThreadPool?
- Update label from another thread [duplicate]
- SqlConnection Thread-Safe?
- Is it good idea to use “Control.CheckForIllegalCrossThreadCalls = false” [duplicate]
- Memory usage in C#