The simplest solution is to replace the property with a field, and
lock { ++progress.CurrentCount; }
(I personally prefer the appearance of preincrement over postincrease, since the “++.” Thing collides in my mind! But postincrementation, of course, will work the same way.)
This will have the added benefit of reducing overhead and competition, since updating a field is faster than calling a method that updates the field.
Of course, encapsulation as a property can also have advantages. IMO, since the syntax of the field and the property is identical, ONLY the advantage of using the property over the field when the property is auto-updated or equivalent is when you have a script in which you might want to deploy one assembly without having to create and deploy dependent assemblies anew. Otherwise, you can use faster fields! If you need to check the value or add a side effect, you simply convert this field to a property and create it again. Therefore, in many practical cases there is no penalty for using the field.
However, we live in a time when many development teams work dogmatically and use tools like StyleCop to ensure their dogmatism. Such tools, unlike coders, are not smart enough to judge when using a field is acceptable, therefore invariably “the rule is simple enough to check even StyleCop”, it becomes “encapsulate fields as properties”, “do not use public fields”, et cetera. ..
source share