473,406 Members | 2,259 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

threading question...

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
2 999
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

65
by: Anthony_Barker | last post by:
I have been reading a book about the evolution of the Basic programming language. The author states that Basic - particularly Microsoft's version is full of compromises which crept in along the...
7
by: Anthony Nystrom | last post by:
What is the correct way to stop a thread? abort? sleep? Will it start up again... Just curious... If the thread is enabling a form, if the form is disposed is the thread as well? Thanks, ...
4
by: Bob | last post by:
- For cleanup, is it sufficient to set a Thread to Nothing after it's done? - It is OK to pass objects out of the thread? (dumb question maybe but I want to be sure) - What's the best way to...
4
by: DBC User | last post by:
I have a background process which reads a table to see if there are any pending requests. If there are any, then it will start a worker thread (only 10 allowed at a time) and executes a method. In...
19
by: frankiespark | last post by:
Hello all, I was perusing the internet for information on threading when I came across this group. Since there seems to be a lot of good ideas and useful info I thought I'd pose a question. ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.