You could also do throws InterruptedException in method definition to avoid try/catch block , or use TimeUnit. MILLISECONDS. sleep() instead.
Thread. sleep is bad! It blocks the current thread and renders it unusable for further work.
Using Thread. sleep() frequently in an automation framework is not a good practice. If the applied sleep is of 5 secs and the web element is displayed in 2 secs only, the extra 3 secs will increase the execution time. And if you use it more often in the framework, the execution time would increase drastically.
C++ language does not provide a sleep function of its own. However, the operating system's specific files like unistd. h for Linux and Windows. h for Windows provide this functionality.
I have a code which when run, it executes series of lines in sequence. I would like to add a pause in between.
Currently, I have it like this
//do work
Thread.Sleep(10800000);
//do work
This however freezes the software, and I think it's because sleep time is way too long. I searched online and I found another work around called Timer. Can someone show me a sample code for Timer which works just like Thread.sleep?
Thank you in advance.
Edit : I need the software to wait for 3 hours before proceeding with rest of the code execution. This software is meant to communicate with machines, and I cannot let the rest of the code execute while waiting for 3 hours.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With