One last (I promise) Threading dilemma

G

Guest

I have a form 2 which contains a datagrid. In form 1 I have a procedure -
"PopulateC" which populates it with values. The instance of form 2 is
"Matrix_C" and it is global.
I determine the data for the grid with:

Dim flag As Boolean = False

Private Sub start_thread(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim thread1 As New System.Threading.Thread(AddressOf bd)
thread1.Start()
End Sub

Private Sub Abort_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
flag = True
End Sub

Public Sub bd()
Some things
Dim i, j, k As Integer
For i = 1 To 1000000
For j = 1 To 1000
If flag = True Then GoTo 1
Next
Next
Some more things
1: flag = False
populateC()
End Sub

When I run the program and click button 1 (and do not abort) I get:
Controls created on one thread cannot be parented to a control on a
different thread. (The debugger points to my populateC procedure)

I understand the error but I am hoping there is a work around (something
like a thread done event) that will enable seamless population of the grid.
 
A

Armin Zingler

mark said:
When I run the program and click button 1 (and do not abort) I get:
Controls created on one thread cannot be parented to a control on a
different thread. (The debugger points to my populateC procedure)

I understand the error but I am hoping there is a work around
(something like a thread done event) that will enable seamless
population of the grid. --

Use grid.Invoke/grid.BeginInvoke to call a sub in the right thread that
fills the grid.


Armin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top