ebortoluzzi
Member
- Joined
- Sep 17, 2009
- Messages
- 8
- Programming Experience
- Beginner
Hi all
I'm facing the problem of updating a RichTextBox (RTB) from a thread with parameters, I used invoke and methodinvoker:
Private Shared ToBeDisplayed(0) As String
Private Sub TmpBTN_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles TmpBTN.Click
Dim thr As Thread = New Thread(AddressOf Me.testhread)
DisplayRTB.Clear()
thr.Start()
End Sub
Private Sub testhread()
Array.Clear(ToBeDisplayed, 0, ToBeDisplayed.Length)
For i As Integer = 0 To 10
ReDim Preserve ToBeDisplayed(i)
For j As Integer = 0 To i
ToBeDisplayed(i) &= j.ToString
Next
If DisplayRTB.InvokeRequired Then
Invoke(New MethodInvoker(AddressOf FillRTB))
Else
FillRTB()
End If
Next
End Sub
Private Sub FillRTB()
Me.DisplayRTB.Lines = ToBeDisplayed
Me.DisplayRTB.Update()
End Sub
To pass the string array ToBeDisplayed() to the FillRTB I declared them at higher level in the class, because MethodInvoker requires a sub without parameters ?!?
It works but I do not like it
I can't believe it is not possible to manage a FillRBT with parameters like:
Private Sub FillRTB(byval MyDisplayed() as string)
Me.DisplayRTB.Lines = MyDisplayed
Me.DisplayRTB.Update()
End Sub
Someone can show/telle me how to proceed, by writing code examples it is the best thank you
I'm facing the problem of updating a RichTextBox (RTB) from a thread with parameters, I used invoke and methodinvoker:
Private Shared ToBeDisplayed(0) As String
Private Sub TmpBTN_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles TmpBTN.Click
Dim thr As Thread = New Thread(AddressOf Me.testhread)
DisplayRTB.Clear()
thr.Start()
End Sub
Private Sub testhread()
Array.Clear(ToBeDisplayed, 0, ToBeDisplayed.Length)
For i As Integer = 0 To 10
ReDim Preserve ToBeDisplayed(i)
For j As Integer = 0 To i
ToBeDisplayed(i) &= j.ToString
Next
If DisplayRTB.InvokeRequired Then
Invoke(New MethodInvoker(AddressOf FillRTB))
Else
FillRTB()
End If
Next
End Sub
Private Sub FillRTB()
Me.DisplayRTB.Lines = ToBeDisplayed
Me.DisplayRTB.Update()
End Sub
To pass the string array ToBeDisplayed() to the FillRTB I declared them at higher level in the class, because MethodInvoker requires a sub without parameters ?!?
It works but I do not like it

I can't believe it is not possible to manage a FillRBT with parameters like:
Private Sub FillRTB(byval MyDisplayed() as string)
Me.DisplayRTB.Lines = MyDisplayed
Me.DisplayRTB.Update()
End Sub
Someone can show/telle me how to proceed, by writing code examples it is the best thank you
