Sign in to follow this  

[.net] c# threads question

Recommended Posts

references work across threads. So keeping a non-local reference to that object is fine. However, you should almost always lock() the object when acessing an object across multiple threads.

However, if you do have many threads and want to reference objects depending on thread, you can do it in a few different ways...

a simple way would be:

Dictionary<Thread, object> threadObjects;



object threadObject = threadObjects[Thread.CurrentThread];

I'm sure there is a better way but that just comes to mind.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this