1 // -------------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All Rights Reserved.
3 // -------------------------------------------------------------------
4 //From \\authoring\Sparkle\Source\1.0.1083.0\Common\Source\Framework
5 namespace System.Activities.Presentation.Internal.PropertyEditing.FromExpression.Framework
8 using System.Diagnostics;
9 using System.Windows.Threading;
13 // A class to execute a method on the UI thread. This must be constructed on the UI thread,
14 // usually by calling UIThreadDispatcher.InitializeDispatcher(). Derive from this and
15 // install your own on UIThreadDispatcher if you want to.
17 internal class UIThreadDispatcher
20 static UIThreadDispatcher dispatcher;
22 private Dispatcher uiThreadDispatcher;
24 // Singleton Management
26 public UIThreadDispatcher()
28 this.uiThreadDispatcher = Dispatcher.CurrentDispatcher;
31 public static UIThreadDispatcher Instance
35 Fx.Assert(dispatcher != null, "Instance getter called before Instance is initialized");
46 public static void InitializeInstance()
48 Instance = new UIThreadDispatcher();
51 public virtual void BeginInvoke(DispatcherPriority priority, Delegate method)
53 if (!this.uiThreadDispatcher.HasShutdownStarted)
55 this.uiThreadDispatcher.BeginInvoke(priority, method);
59 public virtual void BeginInvoke(DispatcherPriority priority, Delegate method, object arg)
61 if (!this.uiThreadDispatcher.HasShutdownStarted)
63 this.uiThreadDispatcher.BeginInvoke(priority, method, arg);
67 public virtual void BeginInvoke(DispatcherPriority priority, Delegate method, object arg, params object[] args)
69 if (!this.uiThreadDispatcher.HasShutdownStarted)
71 this.uiThreadDispatcher.BeginInvoke(priority, method, arg, args);
75 public virtual void Invoke(DispatcherPriority priority, Delegate method)
77 if (!this.uiThreadDispatcher.HasShutdownStarted)
79 this.uiThreadDispatcher.Invoke(priority, method);
83 public virtual void Invoke(DispatcherPriority priority, Delegate method, object arg)
85 if (!this.uiThreadDispatcher.HasShutdownStarted)
87 this.uiThreadDispatcher.Invoke(priority, method, arg);
91 public virtual void Invoke(DispatcherPriority priority, Delegate method, object arg, params object[] args)
93 if (!this.uiThreadDispatcher.HasShutdownStarted)
95 this.uiThreadDispatcher.Invoke(priority, method, arg, args);