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:
10 // The above copyright notice and this permission notice shall be
11 // included in all copies or substantial portions of the Software.
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.
21 // Copyright (c) 2006 Novell, Inc. (http://www.novell.com)
24 // Miguel de Icaza (miguel@novell.com)
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;
34 namespace System.Windows.Threading {
36 public sealed class DispatcherOperation {
37 DispatcherOperationStatus status;
38 DispatcherPriority priority;
39 Dispatcher dispatcher;
41 Delegate delegate_method;
42 object [] delegate_args;
44 internal DispatcherOperation (Dispatcher dis, DispatcherPriority prio)
48 if (Dispatcher.HasShutdownFinished)
49 status = DispatcherOperationStatus.Aborted;
51 status = DispatcherOperationStatus.Pending;
54 internal DispatcherOperation (Dispatcher dis, DispatcherPriority prio, Delegate d)
60 internal DispatcherOperation (Dispatcher dis, DispatcherPriority prio, Delegate d, object arg)
64 delegate_args = new object [1];
65 delegate_args [0] = arg;
68 internal DispatcherOperation (Dispatcher dis, DispatcherPriority prio, Delegate d, object arg, object [] args)
72 delegate_args = new object [args.Length + 1];
73 delegate_args [0] = arg;
74 Array.Copy (args, 0, delegate_args, 1, args.Length);
77 internal void Invoke ()
79 status = DispatcherOperationStatus.Executing;
80 result = delegate_method.DynamicInvoke (delegate_args);
82 status = DispatcherOperationStatus.Completed;
84 if (Completed != null)
85 Completed (this, EventArgs.Empty);
90 status = DispatcherOperationStatus.Aborted;
91 throw new NotImplementedException ();
96 throw new NotImplementedException();
100 public DispatcherOperationStatus Status {
110 public Dispatcher Dispatcher {
116 public DispatcherPriority Priority {
122 if (priority != value){
123 DispatcherPriority old = priority;
125 dispatcher.Reprioritize (this, old);
130 public object Result {
136 public DispatcherOperationStatus Wait ()
138 if (status == DispatcherOperationStatus.Executing)
139 throw new InvalidOperationException ("Already executing");
141 throw new NotImplementedException ();
145 public DispatcherOperationStatus Wait (TimeSpan timeout)
147 if (status == DispatcherOperationStatus.Executing)
148 throw new InvalidOperationException ("Already executing");
150 throw new NotImplementedException ();
153 public event EventHandler Aborted;
154 public event EventHandler Completed;