Successfully added
.NET
by Patrik
Thread Class
The Thread
class allows programmers to create and manage multithreaded applications. It enables concurrent code execution, allowing tasks to run independently for improved performance. Developers can utilize methods like Start, Join, and Sleep to control thread execution, facilitating efficient parallel processing in .NET applications.
Namespace: System.Threading
...see more
The Thread.Sleep
Method Suspends the current thread for the specified amount of time.
Thread.Sleep
is a synchronous method that blocks the current thread for the specified amount of time.- It's generally used in non-async scenarios or when dealing with multi-threading where you explicitly want to pause the execution of the current thread.
- It can introduce responsiveness issues, especially in GUI applications, as it will freeze the UI during the sleep period.
Example:
void MyMethod()
{
// Do something before the delay
Thread.Sleep(1000); // Sleep for 1000 milliseconds (1 second)
// Do something after the delay
}
Referenced in:
Comments