Click here to Skip to main content
15,354,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
Is it possible to modify "any" object in a thread which has not created it?
As we know that if the objects are UI controls, then attempting this would throw an error stating "Control accessed from a thread other than the thread it was created on"
Posted

1 solution

Yes, you just have to be aware of the rules and the process involved. If you google that error message, you'll find all kinds of examples about how to do it.
   
v2
Comments
piushs 1-Sep-10 8:09am
   
Won't it throw similar kind of error? I am confused because objects other than UI controls dont have InvokeRequired property.
Samuel Cherinet 1-Sep-10 11:49am
   
you can access and update objects in different threads. it wouldn't throw an exception for other objects other than UI controls(its a validation imposed on such objects). the only thing would be you have to make sure there is no concurrent update on the object state because you will need to handle those scenarios to prevent data corruption.
There are a bunch of ways provided by .net to make your classes thread safe. the simplest one would be locking ...

hope this shed some light ...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900