473,396 Members | 1,987 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,396 software developers and data experts.

Passing data to a thread

I have seen the following example of passing data to a thread:

Class ThreadData
Public Id As Integer
Public Msg As String
Public Done As Boolean
'
The entry point for the thread

Sub DoTheTask()
For i As Integer = 1 To 10
' Show that the thread received the correct values.
Console.WriteLine("{0} (Thread ID = {1})", msg, id)
' Wait for 0.2 second.
Thread.Sleep(200)
Next
' Let the main thread know that this thread has completed.
Done = True
End Sub
End Class
I am a little puzzled about the use of a public variable here and the
possibilities of it being overwritten by another thread. It raised a
question in my mind about the scope of public variables. Are they public
throughout the whole project or just within a class?

-Jerry
Nov 21 '05 #1
2 1564
Hi,

They are public to the class. If you have several instances of
the class each will have there own public variables. In case you were
wondering the synclock statement will help prevent a variable from being
overwritten.

http://msdn.microsoft.com/library/de...tmsynclock.asp

Ken
-------------------
"Jerry Spence1" <je**********@somewhere.com> wrote in message
news:42**********************@ptn-nntp-reader03.plus.net...
I have seen the following example of passing data to a thread:

Class ThreadData
Public Id As Integer
Public Msg As String
Public Done As Boolean
'
The entry point for the thread

Sub DoTheTask()
For i As Integer = 1 To 10
' Show that the thread received the correct values.
Console.WriteLine("{0} (Thread ID = {1})", msg, id)
' Wait for 0.2 second.
Thread.Sleep(200)
Next
' Let the main thread know that this thread has completed.
Done = True
End Sub
End Class
I am a little puzzled about the use of a public variable here and the
possibilities of it being overwritten by another thread. It raised a
question in my mind about the scope of public variables. Are they public
throughout the whole project or just within a class?

-Jerry

Nov 21 '05 #2
Thanks very much Ken. That clears it up for me

-Jerry
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi,

They are public to the class. If you have several instances of
the class each will have there own public variables. In case you were
wondering the synclock statement will help prevent a variable from being
overwritten.

http://msdn.microsoft.com/library/de...tmsynclock.asp

Ken
-------------------
"Jerry Spence1" <je**********@somewhere.com> wrote in message
news:42**********************@ptn-nntp-reader03.plus.net...
I have seen the following example of passing data to a thread:

Class ThreadData
Public Id As Integer
Public Msg As String
Public Done As Boolean
'
The entry point for the thread

Sub DoTheTask()
For i As Integer = 1 To 10
' Show that the thread received the correct values.
Console.WriteLine("{0} (Thread ID = {1})", msg, id)
' Wait for 0.2 second.
Thread.Sleep(200)
Next
' Let the main thread know that this thread has completed.
Done = True
End Sub
End Class
I am a little puzzled about the use of a public variable here and the
possibilities of it being overwritten by another thread. It raised a
question in my mind about the scope of public variables. Are they public
throughout the whole project or just within a class?

-Jerry

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Alex Vinokur | last post by:
Various forms of argument passing ================================= C/C++ Performance Tests ======================= Using C/C++ Program Perfometer...
0
by: Eric Sabine | last post by:
OK, I'm trying to further my understanding of threading. The code below I wrote as kind of a primer to myself and maybe a template that I could use in the future. What I tried to do was pass data...
22
by: Arne | last post by:
How do I pass a dataset to a webservices? I need to submit a shoppingcart from a pocket PC to a webservice. What is the right datatype? II have tried dataset as a datatype, but I can't get it to...
10
by: Mark Denardo | last post by:
Hi, I have multi-threaded application that requires one particular thread (Non-Form based) to receive data from other threads. I know how to pass control to Form Threads, but I believe there's no...
3
by: Lonewolf | last post by:
Hi all, I'm having difficulties passing data back to managed class from my native class when the data is generated from within a native thread in the native class itself. I will give the following...
0
by: Iain McIntosh | last post by:
Hello if anyone can help me with this I will be very grateful. I have a working version of this program as a windows application, when I try to port it over to c# ASP.NET I can't make it work. ...
14
by: joey.powell | last post by:
I am using VS2005 for a windows forms application. I need to be able to use a worker thread function to offload some processing from the UI thread. The worker thread will need access to a...
2
by: Carl Heller | last post by:
Working in VS2003, .Net 1.1 I'm working on a project where I compare data between two databases. This is a lengthy process, and very data intensive, so I decided to create a class, and thread...
5
by: nass | last post by:
this is a thought experiment. i do not have the time to implement it and test it to see if it works so i am relying on your good will:) thank you in advance im on a linux machine (slackware...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.