#Visual basic net sleep Pc#
This will cause the pc to wait about 5 sec on a pentium 4 PC. Let's write a program of multiple threads to execute the multiple tasks at the same time in the VB.NET application. Create a new sub called 'wait' (or watever you like). To overcome that situation, VB.NET introduces a new concept Multithreading to execute multiple tasks at the same time by creating multiple threads in a program. In this way, the second process has to wait until the first process is completed, and it takes time. When we execute an application, the Main thread will automatically be called to execute the programming logic synchronously, which means it executes one process after another. When two or more processes are executed in a program to simultaneously perform multiple tasks, the process is known as multithreading. The Sleep() method is used to pause the execution of threads for 5 seconds. In the above example, we used a different method of the Thread class such as the Start() method to start execution of the thread, the Join() method is used to stop the execution of the thread until the execution of the thread was completed. Imports System.Threading 'Imports the System.Threading namespace.ĭim th As Thread = New Thread(New ThreadStart(AddressOf PrintInfo))Ĭonsole.WriteLine(" It is a Main Thread")Ĭonsole.WriteLine(" value of j is Second", 5) And the PrintInfo parameter contains an executable statement that is executed when creating a new thread. We need to call the Start() method to start the execution of the new thread because it is initially in the unstart state. A ThreadStart() is a method executed by the new thread. In VB.NET, we can create a thread by extending the Thread class and pass the ThreadStart delegate as an argument to the Thread constructor. And if we create another thread to execute the process in Thread class, the new thread will become the child thread for the main thread. When the execution of a program begins in VB.NET, the Main thread is automatically called to handle the program logic. To create and access a new thread in the Thread class, we need to import the System.Threading namespace. By default, each application has one or more threads to execute each process, and that thread is known as the main thread.
A single thread is used to execute a single logic or task in an application.
And the execution of each process is known as the thread. When two or more processes execute simultaneously in a program, the process is known as multithreading. Next → ← prev VB.NET Multithreading What is VB.NET Thread?