~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/maccore/src/Foundation/NSAction.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
 
33
33
        // Use this for synchronous operations
34
34
        [Register ("__MonoMac_NSActionDispatcher")]
35
 
        internal class NSActionDispatcher : NSObject {
36
 
 
37
 
                public static Selector Selector = new Selector ("apply");
38
 
 
39
 
                NSAction action;
 
35
        internal sealed class NSActionDispatcher : NSObject {
 
36
                public const string SelectorName = "xamarinApplySelector";
 
37
                public static readonly Selector Selector = new Selector (SelectorName);
 
38
 
 
39
                readonly NSAction action;
40
40
 
41
41
                public NSActionDispatcher (NSAction action)
42
42
                {
 
43
                        if (action == null)
 
44
                                throw new ArgumentNullException ("action");
 
45
 
43
46
                        this.action = action;
44
47
                }
45
48
 
46
 
                [Export ("apply")]
 
49
                [Export (SelectorName)]
47
50
                [Preserve (Conditional = true)]
48
51
                public void Apply ()
49
52
                {
57
60
                GCHandle gch;
58
61
                NSAction action;
59
62
 
 
63
#if !MONOTOUCH
60
64
                // This ctor is so that the runtime can create a new instance of this class
61
65
                // if ObjC wants to call release on an instance we've already called Dispose on.
62
66
                // Since we detach the handle from the managed instance when Dispose is called,
63
67
                // there is no way we can get the existing managed instance (which has possibly 
64
68
                // been freed anyway) when ObjC calls release (which ends up in NSObject.NativeRelease).
65
 
                [Obsolete ("Do not use")]
 
69
                [Obsolete ("Do not use, this method is only used internally")]
66
70
                public NSAsyncActionDispatcher (IntPtr handle)
67
71
                        : base (handle)
68
72
                {
69
73
                }
 
74
#endif
70
75
 
71
76
                public NSAsyncActionDispatcher (NSAction action)
72
77
                {
74
79
                        gch = GCHandle.Alloc (this);
75
80
                }
76
81
 
77
 
                [Export ("apply")]
 
82
                [Export (NSActionDispatcher.SelectorName)]
78
83
                [Preserve (Conditional = true)]
79
84
                public void Apply ()
80
85
                {
83
88
                        } finally {
84
89
                                action = null; // this is a one-shot dispatcher
85
90
                                gch.Free ();
 
91
 
 
92
                                //
 
93
                                // Although I would like to call Dispose here, to
 
94
                                // reduce the load on the GC, we have some useful diagnostic
 
95
                                // code in our runtime that is useful to track down
 
96
                                // problems, so we are removing the Dispose and letting
 
97
                                // the GC and our pipeline do their job.
 
98
                                // 
 
99
#if MONOTOUCH
 
100
                                // MonoTouch has fixed the above problems, and we can call
 
101
                                // Dispose here.
86
102
                                Dispose ();
 
103
#endif
87
104
                        }
88
105
                }
89
106
        }