Add placeholders for missing methods:
[mono.git] / mcs / class / WindowsBase / System.Windows.Threading / DispatcherOperation.cs
1 //
2 // Permission is hereby granted, free of charge, to any person obtaining
3 // a copy of this software and associated documentation files (the
4 // "Software"), to deal in the Software without restriction, including
5 // without limitation the rights to use, copy, modify, merge, publish,
6 // distribute, sublicense, and/or sell copies of the Software, and to
7 // permit persons to whom the Software is furnished to do so, subject to
8 // the following conditions:
9 // 
10 // The above copyright notice and this permission notice shall be
11 // included in all copies or substantial portions of the Software.
12 // 
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
15 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
17 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
19 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 //
21 // Copyright (c) 2006 Novell, Inc. (http://www.novell.com)
22 //
23 // Authors:
24 //      Miguel de Icaza (miguel@novell.com)
25 //
26 using System;
27 using System.Collections;
28 using System.Collections.Generic;
29 using System.ComponentModel;
30 using System.Security;
31 using System.Threading;
32 using System.Threading.Tasks;
33
34 namespace System.Windows.Threading {
35
36         public sealed class DispatcherOperation {
37                 DispatcherOperationStatus status;
38                 DispatcherPriority priority;
39                 Dispatcher dispatcher;
40                 object result;
41                 Delegate delegate_method;
42                 object [] delegate_args;
43
44                 internal DispatcherOperation (Dispatcher dis, DispatcherPriority prio)
45                 {
46                         dispatcher = dis;
47                         priority = prio;
48                         if (Dispatcher.HasShutdownFinished)
49                                 status = DispatcherOperationStatus.Aborted;
50                         else
51                                 status = DispatcherOperationStatus.Pending;
52                 }
53                 
54                 internal DispatcherOperation (Dispatcher dis, DispatcherPriority prio, Delegate d)
55                         : this (dis, prio)
56                 {
57                         delegate_method = d;
58                 }
59
60                 internal DispatcherOperation (Dispatcher dis, DispatcherPriority prio, Delegate d, object arg)
61                         : this (dis, prio)
62                 {
63                         delegate_method = d;
64                         delegate_args = new object [1];
65                         delegate_args [0] = arg;
66                 }
67
68                 internal DispatcherOperation (Dispatcher dis, DispatcherPriority prio, Delegate d, object arg, object [] args)
69                         : this (dis, prio)
70                 {
71                         delegate_method = d;
72                         delegate_args = new object [args.Length + 1];
73                         delegate_args [0] = arg;
74                         Array.Copy (args, 0, delegate_args, 1, args.Length);
75                 }
76
77                 internal void Invoke ()
78                 {
79                         status = DispatcherOperationStatus.Executing;
80                         result = delegate_method.DynamicInvoke (delegate_args);
81                                 
82                         status = DispatcherOperationStatus.Completed;
83
84                         if (Completed != null)
85                                 Completed (this, EventArgs.Empty);
86                 }
87                 
88                 public bool Abort ()
89                 {
90                         status = DispatcherOperationStatus.Aborted;
91                         throw new NotImplementedException ();
92                 }
93
94                 public Task Task {
95                         get {
96                                 throw new NotImplementedException();
97                         }
98                 }
99
100                 public DispatcherOperationStatus Status {
101                         get {
102                                 return status;
103                         }
104
105                         internal set {
106                                 status = value;
107                         }
108                 }
109
110                 public Dispatcher Dispatcher {
111                         get {
112                                 return dispatcher;
113                         }
114                 }
115
116                 public DispatcherPriority Priority {
117                         get {
118                                 return priority;
119                         }
120
121                         set {
122                                 if (priority != value){
123                                         DispatcherPriority old = priority;
124                                         priority = value;
125                                         dispatcher.Reprioritize (this, old);
126                                 }
127                         }
128                 }
129
130                 public object Result {
131                         get {
132                                 return result;
133                         }
134                 }
135
136                 public DispatcherOperationStatus Wait ()
137                 {
138                         if (status == DispatcherOperationStatus.Executing)
139                                 throw new InvalidOperationException ("Already executing");
140
141                         throw new NotImplementedException ();
142                 }
143
144                 [SecurityCritical]
145                 public DispatcherOperationStatus Wait (TimeSpan timeout)
146                 {
147                         if (status == DispatcherOperationStatus.Executing)
148                                 throw new InvalidOperationException ("Already executing");
149
150                         throw new NotImplementedException ();
151                 }
152                 
153                 public event EventHandler Aborted;
154                 public event EventHandler Completed;
155         }
156 }