Reply to comment

Just to clarify...

You're not saying that a data model has to be thread-safe in order to use Update Controls. You're saying that IF a program has multiple threads that depend on or change the data model, then the data model must be thread safe. Right? (Personally I avoid any multithreading that involves manual locking, it's way too easy to make a mistake.) And the same rule presumably applies to the navigation model (but if the navigation model is only used by the UI thread, maybe it doesn't have to be thread-safe.)

It might be useful to provide a different version of Independent<T> to support thread safety via locks. Its constructor would accept a lock:

        private object _lock;

        public IndependentMT(T initialValue, object lockObject)
        {
            _value = initialValue;
            _lock = lockObject;
        }
        public T Value
        {
            get {
                lock(_lock) { _independentSentry.OnGet(); return _value; }
            }
            set
            {
                lock(_lock) {
                    if (!object.Equals(value, _value))
                    {
                        _independentSentry.OnSet();
                        _value = value;
                    }
                }
            }
        }

(Independent<T> itself could be extended to support lock-based thread safety, but this would add extra overhead since there'd be a reference to a lock object that might not be used, and the Value property would have to test whether it needs locking on every call.)

Reply

By submitting this form, you accept the Mollom privacy policy.