Hello
I want to cause a time dealy or 100ms in the middle of my code. Can anyone help me on how I can achive this.
Thanks
Simon
Hello
I want to cause a time dealy or 100ms in the middle of my code. Can anyone help me on how I can achive this.
Thanks
Simon
A quick note expanding on 's suggestion for .
The simple "sleep" approach will pause execution of the current thread, so it will work for quick experiments or desktop apps. In ASP.NET, however, pausing a request thread is harmful to scalability because that thread cannot serve other requests while sleeping (Thread.Sleep documentation).
If the goal is a nonblocking short wait inside request handling, prefer an asynchronous delay so the thread can return to the pool while waiting. In modern VB.NET that looks like an async method that awaits a delay:
Public Async Function DoWorkAsync() As Task
' work before
Await Task.Delay(100)
' work after
End Function See the Task.Delay docs for details (Task.Delay documentation).
If the delay is part of background processing (you do not need the request to wait), schedule the work off the request thread instead of sleeping inside the handler. Options include queueing a background work item or using a timer; on supported frameworks use HostingEnvironment.QueueBackgroundWorkItem or the ThreadPool/Timer patterns (QueueBackgroundWorkItem).
For 100 ms specifically, reconsider whether a deliberate delay is required; often a retry/backoff or an event-driven approach is a cleaner solution than inserting sleeps.
Jump to Post— Hamrick 150Use the Thread.Sleep() method.
System.Threading.Thread.Sleep( 100 )
Use the Thread.Sleep() method.
System.Threading.Thread.Sleep( 100 ) Use the Thread.Sleep() method.
System.Threading.Thread.Sleep( 100 )
Thanks :)
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.