Cast Action to NSAction?
-
21-12-2019 - |
题
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 Sys
isn'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.
不隶属于 StackOverflow