ProblemYou want to postpone all activities on the current process thread. SolutionSample code folder: Chapter 14\PauseExecution Put the thread to sleep using the System.Threading.Thread.Sleep() method. This method accepts an amount of time to "sleep," in milliseconds. DiscussionCreate a new Windows Forms application, and add a Button control named Button1. Now add the following code to the form's class template: Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click Threading.Thread.Sleep(3000) MsgBox("Good Morning") End Sub When you run the program and click on Button1, the "Good Morning" message appears after a three-second pause. If your program includes only a single thread (the default behavior), putting the thread to sleep puts the entire application to sleep. If you pass zero (0) to the Sleep() method, the thread pauses temporarily to allow other busy threads to perform some processing. |