Solved

IS ThreadPool.QueueUserWorkItem safe to insert parameters?

Posted on 2011-09-06
2
333 Views
Last Modified: 2012-05-12
client = vary;
data = vary;

ThreadPool.QueueUserWorkItem(
                            delegate
                                {
                                    SendData(Client, data);
                                });

Will my SendData get the correct Client, and data in multi thread application?
My goal is that Client is will be the right guy, during ThreadPool.QueueUserWorkItem called no changing.

Thanks
0
Comment
Question by:JSW21
2 Comments
 
LVL 7

Accepted Solution

by:
Gewgala earned 500 total points
Comment Utility
That should work fine, but one thing you might want to understand is that you're passing the Client object and Data in by value if they are an initiation of a class rather than a raw data type like int or double etc.

This means if you initiate the object on Thread 1 and pass it to Thread 2, Thread 1 will continue execution at the same time Thread 2 does.  If Thread 2 modifies a property on it, the same property is modified for Thread 1 and it won't necessarily happen at the exact same time every time.  You could end up with race conditions if execution is to continue and use the same object on Thread 1 and Thread 2.

I would either pass in a clone of the object to Thread 2 OR cease using the object in Thread 1 until Thread 2 has completed its operation entirely.
0
 

Author Closing Comment

by:JSW21
Comment Utility
Hope this is right, since thread 1 will never reuse/switch the client anywhere.
Thread 1 always created anew.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now