我不完全理解 STATHREAD 属性的作用http://msdn.microsoft.com/en-us/library/system.stathreadattribute.aspx。请看下面的代码:
Imports Project1
Imports System.Threading
Public Class Form1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim t1 As New Thread(AddressOf PersonTest.Test2)
Dim t2 As New Thread(AddressOf PersonTest.Test2)
Dim t3 As New Thread(AddressOf PersonTest.Test2)
t1.Name = "Test1"
t2.Name = "Test2"
t3.Name = "Test3"
t1.Start()
t2.Start()
t3.Start()
End Sub
End Class
代码显式创建了三个线程,因此总共有四个线程,即主线程t1、t2 和t3。
具有一个线程(即主线程)的 Windows 窗体应用程序是否需要 STTHREAD?