16,554
社区成员
发帖
与我相关
我的任务
分享
Imports System
Imports System.Threading
Public Class AClass
Dim filename As String = "r:\test.txt"
Public Sub Method1()
Dim i As Integer
For i = 1 To 10
Dim file As New System.IO.StreamWriter(filename, True) '如果是r:\test.txt 要怎么写? "r:\test.txt"
file.WriteLine("这是类AClass方法method1的内容" + i) 'Text)
file.Close()
'Console.WriteLine("这是类AClass方法method1的内容", i)
Next
End Sub
Public Sub Method2()
Dim i As Integer
For i = 1 To 10
Dim file As New System.IO.StreamWriter(filename, True) '如果是r:\test.txt 要怎么写? "r:\test.txt"
file.WriteLine("这是类AClass方法method2的内容" + i) 'Text)
file.Close()
'Console.WriteLine("这是类AClass方法method2的内容", i)
Next
End Sub
End Class
Public Class ThreadTest
Public Shared Sub Main() '在Main()方法中,我们创建了类Thread的实例。
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 filename As String = "r:\test.txt"
Dim i As Integer
For i = 1 To 10
Dim file As New System.IO.StreamWriter(filename, True) '如果是r:\test.txt 要怎么写? "r:\test.txt"
file.WriteLine("这是Main方法里的内容" + i) 'Text)
file.Close()
' Console.WriteLine("Main方法里的内容", i)
Next
End Sub
End Class