CPF/CPF.Mac/Mac/Foundation/NSAsyncActionDispatcher.cs
2023-11-21 23:05:03 +08:00

41 lines
684 B
C#

using System;
using System.Runtime.InteropServices;
namespace CPF.Mac.Foundation
{
[Register("__MonoMac_NSAsyncActionDispatcher")]
internal class NSAsyncActionDispatcher : NSObject
{
private GCHandle gch;
private NSAction action;
[Obsolete("Do not use, this method is only used internally")]
public NSAsyncActionDispatcher(IntPtr handle)
: base(handle)
{
}
public NSAsyncActionDispatcher(NSAction action)
{
this.action = action;
gch = GCHandle.Alloc(this);
}
[Export("xamarinApplySelector")]
[Preserve(Conditional = true)]
public void Apply()
{
try
{
action();
}
finally
{
action = null;
gch.Free();
}
}
}
}