VB.NET (Visual Basic.net) is a major transformation development tool for Visual Basic for adapting to Microsoft .NET framework. It is more powerful than Visual Basic 6.0 and easier to use. The most important changes are object inheritance, in VB.NET, all manageable types are derived from System.Object. As a programming tool, the most important feature is the recovery of waste fragments, which is controlled by the CLR (Common Language Runtime) and provides better memory management. General type definitions provide better interoperability and synergistic work capabilities, so VB.NET is more powerful and reliable.
In VB.NET, most CLR built-in types have been defined in the System namespace. For example: System.Object, System.Int32, and System.String. It should be noted that a namespace may be embedded in another name space, like System.Data.DataSet classes like System.Data.
Representative is a new concept for the CLR programming model. The representative is a special type of manageable class. When you create a representative instance, you must provide an address that is executed with a method of matching the signature. Once a representative is created, the calling method will become easier.
In the past, when we used VB to develop multi-threaded applications, we were a very painful thing, often multi-threaded program running is a program that will become multi-error! But in VB.NET, this situation has been greatly changed. Now we use VB.NET to handle multithreading and use Java to handle multithreading as simple as simple. Let's take an example to see the multi-threads of VB.NET!
Below is the code of multi-thread Threadtest.vb:
Imports system
Imports system.threading
Public Class Aclass
Public SUB METHOD1 ()
DIM I as integer
FOR i = 1 to 100
Console.writeline ("This is the content of the class ACLASS method", i)
NEXT
End Sub
Public Sub Method2 ()
DIM I as integer
FOR i = 1 to 100
Console.writeline ("This is the content of the class ACLASS method", i)
NEXT
End Sub
END CLASS
Public Class Threadtest
Public Shared Sub Main ()
DIM OBJ AS New Aclass
DIM TH1, TH2 As Thread
TH1 = New Thread (New ThreadStart (Addressof Obj.Method1))
TH1.Start
TH2 = New Thread (New ThreadStart (Addressof Obj.Method2))
TH2.Start
DIM I as integer
FOR i = 1 to 100
Console.WriteLine ("Content in the main method", i)
NEXT
End Sub
END CLASS
Now, let us analyze the above example:
1. We created our own class ACLASS and created two methods: Method1 and Method2.
2. These two methods are very simple, only one for loop, output some information to the output device.
3. We also define another THReadTest to use the class ACLASS created above. 4. In the Main () method, we created an instance of class Thread.
5. Class THREAD can be obtained in the System.Threading namespace, which defines the properties and methods of processing threads.
6. In the constructor of the THREAD, we used class ThreadStart, class ThreadStart is a representative, marking the method of executing the defined method when a thread starts.
7. To perform the defined method, we actually call the start () method of the thread.
8 Use VBC to compile the above procedure:
VBC /out :threadtest.exe threadtest.vb
9. Run the compiled program, we will see the mixed output of the two methods and main () methods we define, indicating that each method runs under its thread.
10. In addition to the above methods, the thread has the following methods:
STOP (): Stop the running of the thread.
Suspend (): Suspend the operation of the thread.
Resume (): Continue thread operation.
Sleep (): Stop the thread for a period of time (in milliseconds).
The above is just a simple example of VB.NET multi-thread, I hope to inspire everyone!