|
■No80994 (トトロ さん) に返信
インスタンス変数を使う方法
Sub Main()
Dim MultiProgram_run = New Thread(AddressOf New User("シン", "ゴジラ").Program_run1xx)
MultiProgram_run.Start()
End Sub
Class User
ReadOnly FirstName As String
ReadOnly LastName As String
Sub New(firstName As String, lastName As String)
Me.FirstName = firstName
Me.LastName = lastName
End Sub
Sub Program_run1xx()
Debug.WriteLine(FirstName & LastName)
End Sub
End Class
引数を渡す方法
Sub Main()
Dim MultiProgram_run = New Thread(AddressOf Program_run1xx)
MultiProgram_run.Start(New User("シン", "ゴジラ"))
End Sub
Class User
Public ReadOnly FirstName As String
Public ReadOnly LastName As String
Sub New(firstName As String, lastName As String)
Me.FirstName = firstName
Me.LastName = lastName
End Sub
End Class
Sub Program_run1xx(arg As Object)
Dim User As User = DirectCast(arg, User)
Debug.WriteLine(User.FirstName & User.LastName)
End Sub
フィールドを共有する方法
Dim FirstName As String
Dim LastName As String
ReadOnly GozillaLock As New Object()
Sub Main()
SyncLock GozillaLock
FirstName = "シン"
LastName = "ゴジラ"
End SyncLock
Dim MultiProgram_run = New Thread(AddressOf Program_run1xx)
MultiProgram_run.Start()
End Sub
Sub Program_run1xx()
SyncLock GozillaLock
Debug.WriteLine(FirstName & LastName)
End SyncLock
End Sub
私が思いついたのは3つでした。
|