Synchronization Context

A context is a set of properties or usage rules that are common to a collection of objects with related run-time execution. The context properties that can be added include policies regarding synchronization, thread affinity, and transactions. In short, a context groups together like-minded objects. In this strategy, we use the SynchronizationAttribute class to enable simple, automatic synchronization for ContextBoundObject objects. Objects that reside in a context and are bound to the context rules are called context-bound objects. .NET automatically associates a synchronization lock with the object, locking it before every method call and releasing the lock (to allow other competing threads to access the object) when the method returns. This is a huge productivity gain, because thread synchronization and concurrency management are among the most difficult tasks that a developer encounters.

The SynchronizationAttribute class is useful to programmers who do not have experience of dealing with synchronization manually because it covers the instance variables, instance methods, and instance fields of the class to which this attribute is applied. It does not, however, handle synchronization of static fields and methods. It also does not help if you have to synchronize specific code blocks; synchronizing the entire object is the price you have to pay for ease of use. SynchronizationAttribute is very handy when programming with System.EnterpriseServices where objects belonging to a context (for example a transaction) are grouped together by the COM+ runtime.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值