By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,693 Members | 1,565 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,693 IT Pros & Developers. It's quick & easy.

threading question...

P: n/a
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...!!!
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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
"Rothariger" <Ro********@discussions.microsoft.com> wrote in message
news:04**********************************@microsof t.com...
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...!!!

Nov 21 '05 #2

P: n/a
hey, i think its a bit late but i want to say thanks... it worked perfectlly...

i forgot this thread... :S

thanks, and salute!

"Some Guy" wrote:
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
"Rothariger" <Ro********@discussions.microsoft.com> wrote in message
news:04**********************************@microsof t.com...
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...!!!


Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.