首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

vb.net多线程有关问题

2012-09-08 
vb.net多线程问题[codeVB.NET][/code]Imports System.ThreadingPublic Class Form1Public Sub Method1()D

vb.net多线程问题
[code=VB.NET][/code]
Imports System.Threading
Public Class Form1
  Public Sub Method1()
  Dim i As Integer
  For i = 1 To 100
  ' Console.Writeline("这是类AClass方法method1的内容", i)
  RichTextBox1.Text &= (("这是method1的内容:" & i) & vbCrLf)
  Next
  End Sub

  Public Sub Method2()
  Dim i As Integer
  For i = 1 To 100
  ' Console.Writeline("这是类AClass方法method2的内容", i)
  RichTextBox1.Text &= (("这是method2的内容:" & i) & vbCrLf)
  Next
  End Sub
  Public Overloads Function invoke(ByVal method As [Delegate])
  Return True
  End Function
  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  'Dim aclass As New AClass
  Dim th1, th2 As Thread
  th1 = New Thread(New ThreadStart(AddressOf Method1))
  th1.Start()
  th2 = New Thread(New ThreadStart(AddressOf Method2))
  th2.Start()
  Dim i As Integer
  For i = 0 To 100
  ' RichTextBox1.Text = Console.WriteLine("Main方法里的内容", i)
  RichTextBox1.Text = ((i) & vbCrLf)
  Next
  End Sub
End Class

  RichTextBox1.Text &= (("这是method1的内容:" & i) & vbCrLf) 这里提示:线程间操作无效: 从不是创建控件“RichTextBox1”的线程访问它。
请问该怎么做呢?

[解决办法]
在load事件中写上: CheckForIllegalCrossThreadCalls = False

热点排行