Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Threading
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-Sep-10 3:04am
piushs131

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
v2
Comments
piushs at 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.
samqty at 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)

  Print Answers RSS
0 OriginalGriff 410
1 Sergey Alexandrovich Kryukov 329
2 Afzaal Ahmad Zeeshan 264
3 BillWoodruff 235
4 CPallini 195
0 OriginalGriff 5,560
1 DamithSL 4,476
2 Maciej Los 3,942
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,175


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 1 Sep 2010
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100