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

Thread questions

Hi, I have two question about threads:
First,
I "share" one instance of the class between main application thread (UI)and
two other worker threads, so there is a possibilty that they can access my
object at the same time. I would like to prevent this situation using "lock"
statments, is it ok? Do I have to "lock" all code where worker thread access
object or only this statments where thread change (modify) shared object?

Second,
I've created some events in thread class, event handlers are placed in main
thread where they update UI controls based on information in
DataReceiveEventArgs.
if (OnDataReceive != null)
{
DataReceiveEventArgs e = new DataReceiveEventArgs("message from thread");
OnDataReceive(this, e);
//invoke?
}
should I call invoke method?

Thanks for any help!
Sorry for my bad English :(

Nov 15 '05 #1
2 2100
"chris" <zx*@msn.com> wrote in message
news:#l**************@TK2MSFTNGP12.phx.gbl...
Hi, I have two question about threads:
First,
I "share" one instance of the class between main application thread (UI)and two other worker threads, so there is a possibilty that they can access my
object at the same time. I would like to prevent this situation using "lock" statments, is it ok? Do I have to "lock" all code where worker thread access object or only this statments where thread change (modify) shared object?


lock() them all, unless you are ok with dirty reads.

You might also want to investigate the ReaderWriterLock in MSDN
Nov 15 '05 #2
"chris" <zx*@msn.com> wrote in message
news:#l**************@TK2MSFTNGP12.phx.gbl...
Hi, I have two question about threads:
First,
I "share" one instance of the class between main application thread (UI)and two other worker threads, so there is a possibilty that they can access my
object at the same time. I would like to prevent this situation using "lock" statments, is it ok? Do I have to "lock" all code where worker thread access object or only this statments where thread change (modify) shared object?


lock() them all, unless you are ok with dirty reads.

You might also want to investigate the ReaderWriterLock in MSDN
Nov 15 '05 #3

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

Similar topics

23
by: Jeff Rodriguez | last post by:
Here's what I want do: Have a main daemon which starts up several threads in a Boss-Queue structure. From those threads, I want them all to sit and watch a queue. Once an entry goes into the...
3
by: Sean | last post by:
Hi all, I have a few questions here regarding UI thread. (1) If I have two windows A and B, then I call B.show() in A. In this case, there will be only 1 UI thread which is the window A UI...
2
by: Frank Rizzo | last post by:
I tried it on dotnet.vb, but got no answers. I'll try it here now. I have an app that listen to data on a certain resource. Data can come in on this resource any time, so I have to listen for it...
2
by: Frank Rizzo | last post by:
I have an app that listen to data on a certain resource.&nbsp; Data can come in on this resource any time, so I have to listen for it the entire time.&nbsp; I wanted to see if what I have is...
0
by: Frank Rizzo | last post by:
I have an app that listen to data on a certain resource. Data can come in on this resource any time, so I have to listen for it the entire time. I wanted to see if what I have is thread-safe and...
3
by: EnglishMan69 | last post by:
Hello All, I am using VB2005 Beta 2 in VS 2005 and am running into a small problem. I need to be able to add a picture box to the main form from within a thread. The program goes to a web...
4
by: iclinux | last post by:
hi there, I'm new to python, and have two questions: a. how to exit the whole process in a thread? b. when thread doing a infinite loops, how to terminate the process?: it seems that the...
27
by: Ritesh Raj Sarraf | last post by:
Hi, I have some basic doubts about thread. I have a list which has items in it which need to be downloaded from the internet. Let's say list is: list_items which has 100 items in it.
1
by: richard.hallgren | last post by:
Hi, I have some questions concerning thread pools. I've marked the questions by number in the text. First I'd like to know when which thread pools an application uses. I know ASP.NET uses the...
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
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
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...
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
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
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.