diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-07-15 10:55:00 +0300 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-07-15 10:55:00 +0300 |
| commit | df9b2580669472d446e109dff88bdfa247b23b1e (patch) | |
| tree | 5503909f4d2c5d41855849b944bc42bdbb788a27 /Software/Visual_Studio | |
| parent | cc425e019d3a7d3494ac15ffe213b6b47b1c64ed (diff) | |
| download | Tango-df9b2580669472d446e109dff88bdfa247b23b1e.tar.gz Tango-df9b2580669472d446e109dff88bdfa247b23b1e.zip | |
Implemented global disable UI Invokations & Property changed events on ExtendedObject.
Some comments on PPC threading.
Diffstat (limited to 'Software/Visual_Studio')
3 files changed, 74 insertions, 9 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Threading/IDispatcherProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Threading/IDispatcherProvider.cs index 4152d0cb9..27a5d1ab1 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Threading/IDispatcherProvider.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Threading/IDispatcherProvider.cs @@ -6,9 +6,21 @@ using System.Threading.Tasks; namespace Tango.PPC.Common.Threading { + /// <summary> + /// Represents a mechanism for invoking actions on the main application thread. + /// </summary> public interface IDispatcherProvider { + /// <summary> + /// Invokes the specified action asynchronously. + /// </summary> + /// <param name="action">The action.</param> void Invoke(Action action); + + /// <summary> + /// Invokes the specified action synchronously. + /// </summary> + /// <param name="action">The action.</param> void InvokeSync(Action action); } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Threading/DefaultDispetcherProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Threading/DefaultDispetcherProvider.cs index c33233573..0051ca329 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Threading/DefaultDispetcherProvider.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Threading/DefaultDispetcherProvider.cs @@ -8,20 +8,36 @@ using Tango.PPC.Common.Threading; namespace Tango.PPC.UI.Threading { + /// <summary> + /// Represents the default PPC <see cref="IDispatcherProvider"/> which will invoke action on the current application dispatcher. + /// </summary> + /// <seealso cref="Tango.PPC.Common.Threading.IDispatcherProvider" /> public class DefaultDispetcherProvider : IDispatcherProvider { private Dispatcher _dispatcher; - public DefaultDispetcherProvider(Dispatcher dispacther) + /// <summary> + /// Initializes a new instance of the <see cref="DefaultDispetcherProvider"/> class. + /// </summary> + /// <param name="dispatcher">The dispatcher.</param> + public DefaultDispetcherProvider(Dispatcher dispatcher) { - _dispatcher = dispacther; + _dispatcher = dispatcher; } + /// <summary> + /// Invokes the specified action asynchronously. + /// </summary> + /// <param name="action">The action.</param> public void Invoke(Action action) { _dispatcher.BeginInvoke(action); } + /// <summary> + /// Invokes the specified action synchronously. + /// </summary> + /// <param name="action">The action.</param> public void InvokeSync(Action action) { _dispatcher.Invoke(action); diff --git a/Software/Visual_Studio/Tango.Core/ExtendedObject.cs b/Software/Visual_Studio/Tango.Core/ExtendedObject.cs index cafafef4f..03ac703ae 100644 --- a/Software/Visual_Studio/Tango.Core/ExtendedObject.cs +++ b/Software/Visual_Studio/Tango.Core/ExtendedObject.cs @@ -23,6 +23,16 @@ namespace Tango.Core public class ExtendedObject : INotifyPropertyChanged { /// <summary> + /// Gets or sets a value indicating whether to globally disable property changed on extended objects. + /// </summary> + public static bool DisablePropertyChanged { get; set; } + + /// <summary> + /// Gets or sets a value indicating whether to globally disable UI invokations on extended objects. + /// </summary> + public static bool DisableUIInvokation { get; set; } + + /// <summary> /// Occurs when after InvalidateRelayCommands is called. /// </summary> [field: NonSerialized] @@ -60,7 +70,10 @@ namespace Tango.Core /// <param name="propName">Name of the property.</param> protected virtual void RaisePropertyChanged(String propName) { - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName)); + if (!DisablePropertyChanged) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName)); + } } /// <summary> @@ -69,7 +82,10 @@ namespace Tango.Core /// <param name="propName">Name of the property.</param> protected virtual void RaisePropertyChangedAuto([CallerMemberName] string caller = null) { - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(caller)); + if (!DisablePropertyChanged) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(caller)); + } } /// <summary> @@ -77,7 +93,7 @@ namespace Tango.Core /// </summary> protected virtual void InvalidateRelayCommands() { - Application.Current.Dispatcher.BeginInvoke(new Action(() => + InvokeUI(() => { foreach (var prop in this.GetType().GetProperties().Where(x => x.PropertyType == typeof(RelayCommand))) { @@ -90,7 +106,7 @@ namespace Tango.Core } RelayCommandsInvalidated?.Invoke(this, new EventArgs()); - })); + }); } /// <summary> @@ -109,7 +125,14 @@ namespace Tango.Core /// <param name="action">The action.</param> protected virtual void InvokeUI(Action action) { - Application.Current.Dispatcher.BeginInvoke(action); + if (!DisableUIInvokation) + { + Application.Current.Dispatcher.BeginInvoke(action); + } + else + { + action(); + } } /// <summary> @@ -118,7 +141,14 @@ namespace Tango.Core /// <param name="action">The action.</param> protected virtual void InvokeUIOnIdle(Action action) { - Application.Current.Dispatcher.BeginInvoke(action, DispatcherPriority.ContextIdle); + if (!DisableUIInvokation) + { + Application.Current.Dispatcher.BeginInvoke(action, DispatcherPriority.ContextIdle); + } + else + { + action(); + } } /// <summary> @@ -127,7 +157,14 @@ namespace Tango.Core /// <param name="action">The action.</param> protected virtual void InvokeUINow(Action action) { - Application.Current.Dispatcher.Invoke(action); + if (!DisableUIInvokation) + { + Application.Current.Dispatcher.Invoke(action); + } + else + { + action(); + } } } } |
