threading question...

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hello, i have a question of threads, im making some tests, and i want to get
a value of a variable inside a thread, but i want to retrieve from outside of
it..
was it clear?


'when i clic the button its start the thread. completes a variable in
the class, and starts.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim Class1 As New TPruebas
Dim myT As New Threading.Thread(AddressOf Class1.myThread)
Class1.myInt = 100
myT.Start()
End Sub

Public Class TPruebas
Public myInt As Double
Public incInt As Double
Public Sub myThread()
For incInt = 0 To myInt * 1000
Thread.Sleep(250)
'I put the values of the for in a textbox so i know that the
thread is running.
txtCount.text = incInt
Next
End Sub
End Class


'now when i push this button, i want that this sub, retrieves the values
from the thread, all my trys where fails. some one could tell me, how to do
it, and if this is posible?
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

End Sub



i didnt find a way of do it...


thanks...!!!
 
Your class TPruebas is declared locally in your Button1_Click so you can't
access the values you want form the Button2_Click event. That's why it
fails. Declare it outside of your click event. You could also raise an event
from your class returning the value when complete.

Dim Class1 As New TPruebas

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim myT As New Threading.Thread(AddressOf Class1.myThread)
Class1.myInt = 100
myT.Start()

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

txtCount.text = Class1.incInt

End Sub
 
hey, i think its a bit late but i want to say thanks... it worked perfectlly...

i forgot this thread... :S

thanks, and salute!
 

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

Back
Top