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;
33 namespace System.Windows.Threading {
35 public sealed class DispatcherOperation {
36 DispatcherOperationStatus status;
37 DispatcherPriority priority;
38 Dispatcher dispatcher;
40 Delegate delegate_method;
41 object [] delegate_args;
43 internal DispatcherOperation (Dispatcher dis, DispatcherPriority prio)
47 if (Dispatcher.HasShutdownFinished)
48 status = DispatcherOperationStatus.Aborted;
50 status = DispatcherOperationStatus.Pending;
53 internal DispatcherOperation (Dispatcher dis, DispatcherPriority prio, Delegate d)
59 internal DispatcherOperation (Dispatcher dis, DispatcherPriority prio, Delegate d, object arg)
63 delegate_args = new object [1];
64 delegate_args [0] = arg;
67 internal DispatcherOperation (Dispatcher dis, DispatcherPriority prio, Delegate d, object arg, object [] args)
71 delegate_args = new object [args.Length + 1];
72 delegate_args [0] = arg;
73 Array.Copy (args, 0, delegate_args, 1, args.Length);
76 internal void Invoke ()
78 status = DispatcherOperationStatus.Executing;
79 result = delegate_method.DynamicInvoke (delegate_args);
81 status = DispatcherOperationStatus.Completed;
83 if (Completed != null)
84 Completed (this, EventArgs.Empty);
89 status = DispatcherOperationStatus.Aborted;
90 throw new NotImplementedException ();
93 public DispatcherOperationStatus Status {
103 public Dispatcher Dispatcher {
109 public DispatcherPriority Priority {
115 if (priority != value){
116 DispatcherPriority old = priority;
118 dispatcher.Reprioritize (this, old);
123 public object Result {
129 public DispatcherOperationStatus Wait ()
131 if (status == DispatcherOperationStatus.Executing)
132 throw new InvalidOperationException ("Already executing");
134 throw new NotImplementedException ();
138 public DispatcherOperationStatus Wait (TimeSpan timeout)
140 if (status == DispatcherOperationStatus.Executing)
141 throw new InvalidOperationException ("Already executing");
143 throw new NotImplementedException ();
146 public event EventHandler Aborted;
147 public event EventHandler Completed;