I've got question you may consider simple. Im rather new to C#, and I am not quiet sure about one thing. I've found somewhere, that one of ways of synchronizing access of few threads to one object is by using [Synchronization] attribute and ContextBoundObject class derivance. I am not sure how does it work. I mean .. in C/C++, where object of some class may contain OBJECTS of another class, using such an attribute (if it would be possible in C/C++) is rather easy to understand, because object of a class containing PHYSICAL OBJECTS of another class could be considered as a big can in memory. In C# object of one class contains REFERENCES to objects of another class. Now considering sample code :
Expand|Select|Wrap|Line Numbers
- [Synchronization]
- class X : ContextBoundObject
- {
- private DataSet ds;
- public X(..) {...}
- ...
- ...
- public DataTable MainTable
- {
- get
- {
- return ds.Tables["maintable"];
- }
- }
- ...
- ...
- }
- class Program
- {
- ...
- X x = new X(...);
- ...
- }
is access to MainTable also synchronized ? I mean.. if one thread is modifying MainTable(which should be "part" of object x of class X ) then no other threads can access x.MainTable, right ? And what in case, when reference X.ds.Tables["maintable"] will change ( new DataTable will be assigned ) ?
I'm not sure if anything what i wrote is understandable, but if anyone gets what i meant, please help :) Thanks a lot.