[reflection] Coop handles icalls in System.Reflection and System.RuntimeTypeHandle...
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / System.Activities.Presentation / System / Activities / Presentation / Base / Core / Internal / PropertyEditing / FromExpression / Framework / UIThreadDispatcher.cs
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
6 {
7     using System;
8     using System.Diagnostics;
9     using System.Windows.Threading;
10     using System.Runtime;
11
12     // <summary>
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.
16     // </summary>
17     internal class UIThreadDispatcher
18     {
19
20         static UIThreadDispatcher dispatcher;
21         // fields
22         private Dispatcher uiThreadDispatcher;
23
24         // Singleton Management
25
26         public UIThreadDispatcher()
27         {
28             this.uiThreadDispatcher = Dispatcher.CurrentDispatcher;
29         }
30
31         public static UIThreadDispatcher Instance
32         {
33             get
34             {
35                 Fx.Assert(dispatcher != null, "Instance getter called before Instance is initialized");
36
37                 return dispatcher;
38             }
39             set
40             {
41                 dispatcher = value;
42             }
43         }
44
45
46         public static void InitializeInstance()
47         {
48             Instance = new UIThreadDispatcher();
49         }
50
51         public virtual void BeginInvoke(DispatcherPriority priority, Delegate method)
52         {
53             if (!this.uiThreadDispatcher.HasShutdownStarted)
54             {
55                 this.uiThreadDispatcher.BeginInvoke(priority, method);
56             }
57         }
58
59         public virtual void BeginInvoke(DispatcherPriority priority, Delegate method, object arg)
60         {
61             if (!this.uiThreadDispatcher.HasShutdownStarted)
62             {
63                 this.uiThreadDispatcher.BeginInvoke(priority, method, arg);
64             }
65         }
66
67         public virtual void BeginInvoke(DispatcherPriority priority, Delegate method, object arg, params object[] args)
68         {
69             if (!this.uiThreadDispatcher.HasShutdownStarted)
70             {
71                 this.uiThreadDispatcher.BeginInvoke(priority, method, arg, args);
72             }
73         }
74
75         public virtual void Invoke(DispatcherPriority priority, Delegate method)
76         {
77             if (!this.uiThreadDispatcher.HasShutdownStarted)
78             {
79                 this.uiThreadDispatcher.Invoke(priority, method);
80             }
81         }
82
83         public virtual void Invoke(DispatcherPriority priority, Delegate method, object arg)
84         {
85             if (!this.uiThreadDispatcher.HasShutdownStarted)
86             {
87                 this.uiThreadDispatcher.Invoke(priority, method, arg);
88             }
89         }
90
91         public virtual void Invoke(DispatcherPriority priority, Delegate method, object arg, params object[] args)
92         {
93             if (!this.uiThreadDispatcher.HasShutdownStarted)
94             {
95                 this.uiThreadDispatcher.Invoke(priority, method, arg, args);
96             }
97         }
98     }
99 }
100