I was wondering if there's a cleaner work-around for this:

public class Sys
{
    public static void DispatchAsync(Action action)
    {
        DispatchQueue.MainQueue.DispatchAsync(() => { action(); });
    }
}

This Sys class is platform-neutral, so Action should be the method parameter type, but GCD's DispatchAsync won't take action if it's an Action type, only as an NSAction or the work-around here . . .

有帮助吗?

解决方案

The class Sysisn't platform neutral if it is using Grand Central Dispatch. Better use Task.Run() and async/await.

And no, there is no better way than your workaround.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top