From df9b2580669472d446e109dff88bdfa247b23b1e Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Sun, 15 Jul 2018 10:55:00 +0300 Subject: Implemented global disable UI Invokations & Property changed events on ExtendedObject. Some comments on PPC threading. --- .../Threading/IDispatcherProvider.cs | 12 +++++ .../Threading/DefaultDispetcherProvider.cs | 20 ++++++++- .../Visual_Studio/Tango.Core/ExtendedObject.cs | 51 +++++++++++++++++++--- 3 files changed, 74 insertions(+), 9 deletions(-) (limited to 'Software/Visual_Studio') 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 { + /// + /// Represents a mechanism for invoking actions on the main application thread. + /// public interface IDispatcherProvider { + /// + /// Invokes the specified action asynchronously. + /// + /// The action. void Invoke(Action action); + + /// + /// Invokes the specified action synchronously. + /// + /// The action. 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 { + /// + /// Represents the default PPC which will invoke action on the current application dispatcher. + /// + /// public class DefaultDispetcherProvider : IDispatcherProvider { private Dispatcher _dispatcher; - public DefaultDispetcherProvider(Dispatcher dispacther) + /// + /// Initializes a new instance of the class. + /// + /// The dispatcher. + public DefaultDispetcherProvider(Dispatcher dispatcher) { - _dispatcher = dispacther; + _dispatcher = dispatcher; } + /// + /// Invokes the specified action asynchronously. + /// + /// The action. public void Invoke(Action action) { _dispatcher.BeginInvoke(action); } + /// + /// Invokes the specified action synchronously. + /// + /// The action. 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 @@ -22,6 +22,16 @@ namespace Tango.Core [Serializable] public class ExtendedObject : INotifyPropertyChanged { + /// + /// Gets or sets a value indicating whether to globally disable property changed on extended objects. + /// + public static bool DisablePropertyChanged { get; set; } + + /// + /// Gets or sets a value indicating whether to globally disable UI invokations on extended objects. + /// + public static bool DisableUIInvokation { get; set; } + /// /// Occurs when after InvalidateRelayCommands is called. /// @@ -60,7 +70,10 @@ namespace Tango.Core /// Name of the property. protected virtual void RaisePropertyChanged(String propName) { - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName)); + if (!DisablePropertyChanged) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName)); + } } /// @@ -69,7 +82,10 @@ namespace Tango.Core /// Name of the property. protected virtual void RaisePropertyChangedAuto([CallerMemberName] string caller = null) { - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(caller)); + if (!DisablePropertyChanged) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(caller)); + } } /// @@ -77,7 +93,7 @@ namespace Tango.Core /// 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()); - })); + }); } /// @@ -109,7 +125,14 @@ namespace Tango.Core /// The action. protected virtual void InvokeUI(Action action) { - Application.Current.Dispatcher.BeginInvoke(action); + if (!DisableUIInvokation) + { + Application.Current.Dispatcher.BeginInvoke(action); + } + else + { + action(); + } } /// @@ -118,7 +141,14 @@ namespace Tango.Core /// The action. protected virtual void InvokeUIOnIdle(Action action) { - Application.Current.Dispatcher.BeginInvoke(action, DispatcherPriority.ContextIdle); + if (!DisableUIInvokation) + { + Application.Current.Dispatcher.BeginInvoke(action, DispatcherPriority.ContextIdle); + } + else + { + action(); + } } /// @@ -127,7 +157,14 @@ namespace Tango.Core /// The action. protected virtual void InvokeUINow(Action action) { - Application.Current.Dispatcher.Invoke(action); + if (!DisableUIInvokation) + { + Application.Current.Dispatcher.Invoke(action); + } + else + { + action(); + } } } } -- cgit v1.3.1