public static void ExecuteUIHelper(DispatcherObject elt, Action worker) { elt.Dispatcher.BeginInvoke( new Action( delegate() { worker(); } )); }
public static void ExecuteBlockerUIHelper(DispatcherObject elt, Action worker) { CountdownEvent _countdown = new CountdownEvent(1); elt.Dispatcher.BeginInvoke( new Action( delegate() { worker(); _countdown.Signal(); } )); _countdown.Wait(3500); }
private static void ApplyThemeImpl(DispatcherObject @object, ResourceDictionary resources, Theme theme) { Contract.Requires<ArgumentNullException>(resources != null); ResourceDictionary current; if (CurrentThemes.TryGetValue(@object, out current)) { resources.MergedDictionaries.Remove(current); } if (theme != null && theme.Uri != null) { var resourceDictionary = Application.LoadComponent(theme.Uri) as ResourceDictionary; if (resourceDictionary != null) { resources.MergedDictionaries.Add(resourceDictionary); CurrentThemes[@object] = resourceDictionary; } } }
/// <summary> /// </summary> public static void DisableImmComposition(DispatcherObject dispatcher) { if (dispatcher == null) { throw new ArgumentNullException("dispatcher"); } if (!_threadMgrFailed) { if (_threadMgr == null) { Msctr.TF_CreateThreadMgr(out _threadMgr); if (_threadMgr == null) { _threadMgrFailed = true; return; } } dispatcher.Dispatcher.BeginInvoke( DispatcherPriority.Background , new DispatcherOperationCallback( delegate { IntPtr ptr; _threadMgr.GetFocus(out ptr); if (ptr == IntPtr.Zero) { _threadMgr.SetFocus(_documentMgr); } return null; } ) , null ); } }
/// <summary> /// Safely invokes an action on a dispatcher object. /// </summary> /// <param name="This">This DispatcherObject.</param> /// <param name="action">The action.</param> /// <param name="async">if set to <c>true</c> we'll be going to make an asynchronous call to the dispatcher; otherwise, we'll wait till execution ends.</param> /// <returns><c>true</c> when the task could be executed on the current thread immediately; otherwise, <c>false</c>.</returns> public static bool SafelyInvoke(this DispatcherObject This, Action action, bool @async = false, DispatcherPriority dispatcherPriority = DispatcherPriority.Normal) { Contract.Requires(This != null); Contract.Requires(action != null); var dispatcher = This.Dispatcher; Contract.Assume(dispatcher != null); if (dispatcher.CheckAccess()) { action(); return(true); } if (@async) { dispatcher.BeginInvoke(action, dispatcherPriority); } else { dispatcher.Invoke(action, dispatcherPriority); } return(false); }
internal void AddOwner(DispatcherObject owner) { if (this.inheritanceContext == null) { this.inheritanceContext = owner as DependencyObject; if (this.inheritanceContext == null) { this.inheritanceContext = new DependencyObject(); this.inheritanceContext.DetachFromDispatcher(); } else { this.AddInheritanceContextToValues(); } } UIElement frameworkElement = owner as UIElement; if (frameworkElement != null) { if (this.ownerFEs == null) { this.ownerFEs = new List<UIElement>(1); } else if (this.ownerFEs.Contains(frameworkElement) && this.ContainsCycle(this)) { throw new InvalidOperationException("ResourceDictionaryInvalidMergedDictionary"); } if (this.HasImplicitStyles) { ////frameworkElement.ShouldLookupImplicitStyles = true; } this.ownerFEs.Add(frameworkElement); } this.AddOwnerToAllMergedDictionaries(owner); this.TryInitialize(); }
/// <summary> /// Checks if to CAO have the same context affinity. This is for example important for /// ContainerVisual.Children.Add to ensure that the scene graph is homogenously build out /// of object that have the same context affinity. /// </summary> /// <param name="reference">Reference to which to compare to. This argument is usually the this /// pointer and can not be null.</param> /// <param name="other">Object for which the check is performed.</param> /// <remarks> /// Example: /// /// class Visual /// { /// ... /// void Add(Visual child) /// { /// VerifyContext(this); /// AssertSameContext(this, child); /// ... /// } /// } /// /// Note that VerifyContext(A) AND AssertSameContext(A, B) implies that VerifyContext(B) holds. Hence you /// don't need to check the context for each argument if you assert the same context. /// </remarks> internal static void AssertSameContext( DispatcherObject reference, DispatcherObject other) { Debug.Assert(reference != null, "The reference object can not be null."); // DispatcherObjects may be created with the option of becoming unbound. // An unbound DO may be created without a Dispatcher or may detach from // its Dispatcher (e.g., a Freezable). Unbound DOs return null for their // Dispatcher and should be accepted anywhere. if (other != null && reference.Dispatcher != null && other.Dispatcher != null && reference.Dispatcher != other.Dispatcher) { throw new ArgumentException(SR.Get(SRID.MediaSystem_ApiInvalidContext)); } }
/// <summary> /// Adds the given owner to all merged dictionaries of this ResourceDictionary /// </summary> /// <param name="owner"></param> private void AddOwnerToAllMergedDictionaries(DispatcherObject owner) { if (_mergedDictionaries != null) { for (int i = 0; i < _mergedDictionaries.Count; i++) { _mergedDictionaries[i].AddOwner(owner); } } }
// Check if the given is an owner to this dictionary internal bool ContainsOwner(DispatcherObject owner) { FrameworkElement fe = owner as FrameworkElement; if (fe != null) { return (_ownerFEs != null && _ownerFEs.Contains(fe)); } else { FrameworkContentElement fce = owner as FrameworkContentElement; if (fce != null) { return (_ownerFCEs != null && _ownerFCEs.Contains(fce)); } else { Application app = owner as Application; if (app != null) { return (_ownerApps != null && _ownerApps.Contains(app)); } } } return false; }
public WpfDispatchService(DispatcherObject app) { Dispatcher = app.Dispatcher; SyncContext = new DispatcherSynchronizationContext(Dispatcher); }
/// <summary> /// Constructor /// </summary> /// <param name="dispatcher">Dispatcher object</param> public MainViewModel(DispatcherObject dispatcher) { _dispatcher = dispatcher; }
private void RemoveOwnerFromAllMergedDictionaries(DispatcherObject owner) { if (this.mergedDictionaries != null) { for (int i = 0; i < this.mergedDictionaries.Count; i++) { this.mergedDictionaries[i].RemoveOwner(owner); } } }
private ICollection<PSObject> Invoke(DispatcherObject uie, PSVariable[] variables, params object[] arguments) { return uie.Dispatcher.Invoke((InvokeDelegate)Invoker, variables, arguments) as ICollection<PSObject>; }
public static DispatcherProcessingDisabled DisableProcessing(this DO @do) => @do.Dispatcher.DisableProcessing();
public static TResult Sync <TResult>(this DO @do, Func <TResult> action) => (TResult)@do.Dispatcher.Invoke(action, Empty <object>());
public static void Sync(this DO @do, Action action) => @do.Dispatcher.Invoke(action, Empty <object>());
public static Task Run <TArg>(this DO @do, Action <TArg> action, TArg arg0) => @do.Dispatcher.BeginInvoke(action, new object[] { arg0 }).Task;
public static Task Run(this DO @do, Action action, params object[] args) => @do.BeginInvoke(action, args).Task;
public static Op Async(this DO @do, Action action, params object[] args) => @do.Dispatcher.BeginInvoke(action, args);
internal bool ContainsOwner(DispatcherObject owner) { UIElement frameworkElement = owner as UIElement; if (frameworkElement != null) { if (this.ownerFEs == null) { return false; } return this.ownerFEs.Contains(frameworkElement); } return false; }
internal void RemoveOwner(DispatcherObject owner) { UIElement frameworkElement = owner as UIElement; if (frameworkElement != null && this.ownerFEs != null) { this.ownerFEs.Remove(frameworkElement); if (this.ownerFEs.Count == 0) { this.ownerFEs = null; } } if (owner == this.inheritanceContext) { this.RemoveInheritanceContextFromValues(); this.inheritanceContext = null; } this.RemoveOwnerFromAllMergedDictionaries(owner); }
static void UiInvoke(DispatcherObject img, Action act) { img.Dispatcher.BeginInvoke(DispatcherPriority.SystemIdle,act); }
// Add an owner for this dictionary internal void AddOwner(DispatcherObject owner) { if (_inheritanceContext == null) { // the first owner gets to be the InheritanceContext for // all the values in the dictionary that want one. _inheritanceContext = owner as DependencyObject; if (_inheritanceContext != null) { // set InheritanceContext for the existing values AddInheritanceContextToValues(); } else { // if the first owner is ineligible, use a dummy _inheritanceContext = new DependencyObject(); _inheritanceContext.DetachFromDispatcher(); // do not call AddInheritanceContextToValues - // the owner is an Application, and we'll be // calling SealValues soon, which takes care // of InheritanceContext as well } } FrameworkElement fe = owner as FrameworkElement; if (fe != null) { if (_ownerFEs == null) { _ownerFEs = new WeakReferenceList(1); } else if (_ownerFEs.Contains(fe) && ContainsCycle(this)) { throw new InvalidOperationException(SR.Get(SRID.ResourceDictionaryInvalidMergedDictionary)); } // Propagate the HasImplicitStyles flag to the new owner if (HasImplicitStyles) { fe.ShouldLookupImplicitStyles = true; } _ownerFEs.Add(fe); } else { FrameworkContentElement fce = owner as FrameworkContentElement; if (fce != null) { if (_ownerFCEs == null) { _ownerFCEs = new WeakReferenceList(1); } else if (_ownerFCEs.Contains(fce) && ContainsCycle(this)) { throw new InvalidOperationException(SR.Get(SRID.ResourceDictionaryInvalidMergedDictionary)); } // Propagate the HasImplicitStyles flag to the new owner if (HasImplicitStyles) { fce.ShouldLookupImplicitStyles = true; } _ownerFCEs.Add(fce); } else { Application app = owner as Application; if (app != null) { if (_ownerApps == null) { _ownerApps = new WeakReferenceList(1); } else if (_ownerApps.Contains(app) && ContainsCycle(this)) { throw new InvalidOperationException(SR.Get(SRID.ResourceDictionaryInvalidMergedDictionary)); } // Propagate the HasImplicitStyles flag to the new owner if (HasImplicitStyles) { app.HasImplicitStylesInResources = true; } _ownerApps.Add(app); // An Application ResourceDictionary can be accessed across threads CanBeAccessedAcrossThreads = true; // Seal all the styles and templates in this app dictionary SealValues(); } } } AddOwnerToAllMergedDictionaries(owner); // This dictionary will be marked initialized if no one has called BeginInit on it. // This is done now because having an owner is like a parenting operation for the dictionary. TryInitialize(); }
// Remove an owner for this dictionary internal void RemoveOwner(DispatcherObject owner) { FrameworkElement fe = owner as FrameworkElement; if (fe != null) { if (_ownerFEs != null) { _ownerFEs.Remove(fe); if (_ownerFEs.Count == 0) { _ownerFEs = null; } } } else { FrameworkContentElement fce = owner as FrameworkContentElement; if (fce != null) { if (_ownerFCEs != null) { _ownerFCEs.Remove(fce); if (_ownerFCEs.Count == 0) { _ownerFCEs = null; } } } else { Application app = owner as Application; if (app != null) { if (_ownerApps != null) { _ownerApps.Remove(app); if (_ownerApps.Count == 0) { _ownerApps = null; } } } } } if (owner == _inheritanceContext) { RemoveInheritanceContextFromValues(); _inheritanceContext = null; } RemoveOwnerFromAllMergedDictionaries(owner); }
/// <summary> /// 实例化一个后台管理View Mode对象 /// </summary> private ManagementViewModel() { lockobj = new Object(); _TradeJuJianInfo = new ClientTradeJuJianInfo(); _dpObj = new DependencyObject(); LogRequestInfo = new LogRequestInformation(); ClientAccFilter = new ClientAccountFilter(); OnlineClientAccFilter = new ClientAccountFilter(); MarketOrderRequestInfo = new RequestInformationBase(); PendingOrderRequestInfo = new RequestInformationBase(); HedgingTradeRequestInfo = new RequestInformationBase(); StatementsRequestInfo = new StatementsRequestInformation(); _businessService = new BusinessServiceProvider(); _tradeService = new TradeServiceProvider(); _bzjService = new BzjServiceProvider(); // GetNewsCondition = new SelectCondition(); _BzjInfoInformation = new BzjInfoInformation(); TakeGoodsDetialSelectCondition = new SelectCondition(); _TakeGoodsDetailList = new ObservableCollection<BzjTakeGoodsDetailEntity>(); BindingJgjAccountCondition = new SelectCondition(); _DeliveryGoodsCondition = new SelectCondition(); _DeliveryGoodsList = new ObservableCollection<BzjDeliverEntity>(); _TakeGoodsCondition = new SelectCondition(); _TakeGoodsList = new ObservableCollection<BzjOrderEntity>(); _BackGoodsCondition = new SelectCondition(); _BackGoodsList = new ObservableCollection<BzjOrderEntity>(); _JgjGoodsCondition = new SelectCondition(); _JgjGoodsList = new ObservableCollection<BzjOrderEntity>(); _DeliveryBackGoodsCondition = new SelectCondition(); _DeliveryBackGoodsList = new List<BzjRecoverOrder>(); _GetClerkCondition = new SelectCondition(); _ClerkAccountList = new ObservableCollection<BzjClerk>(); InterOfficeSelectCondtion = new SelectCondition(); ClientAccountSelectCondition = new SelectCondition(); OnlineAccountSelectCondition = new SelectCondition(); ManagerAccountSelectCondition = new SelectCondition(); OrgAccountSelectCondition = new SelectCondition(); FundReportSelectCondition = new SelectCondition(); OrgSelectCondition = new SelectCondition(); ChuJinSelectCondition = new SelectCondition(); TerminationSelectCondition = new SelectCondition(); TradeConfigInfoList = new ObservableCollection<TradeConfigInfo>(); NewsList = new ObservableCollection<NewsInfo>(); ArtilesList = new ObservableCollection<NewsInfo>(); AdvertList = new ObservableCollection<AdvertInfo>(); GetNewsCondition = new SelectCondition(); GetArticlesCondition = new SelectCondition(); GetAdvertCondition = new SelectCondition(); FundReportList = new ObservableCollection<FundChangeInformation>(); ChuJinList = new ObservableCollection<TradeChuJinInformation>(); OrgList = new ObservableCollection<OrgInfo>(); UserGroups = new ObservableCollection<UserGroup>(); UserGroupSelectCon = new SelectCondition(); GroupAccounts = new ObservableCollection<ClientAccount>(); }
public WpfDispatchServices(DispatcherObject app) { Dispatcher = app.Dispatcher; }