【发布时间】:2017-06-07 18:24:16
【问题描述】:
System.Threading.Timer 不适用于 PCL(可移植类库)
System.Threading.Timer tmr = new System.Threading.Timer(this.Method1,"Obj", 10000, System.Threading.Timeout.Infinite);
我在 PCL 中找不到任何等效项。
我在附近找到了一些东西
System.Threading.Tasks.Task.Delay(10000)
但这会阻塞用户界面
而 system.Threading.timer 没有阻塞 UI
基本上我想在延迟后调用一个方法而不阻塞来自 PCL 的 UI
请澄清这一点。
【问题讨论】:
-
你为什么不直接
await它,这样它就不会阻塞用户界面?这是一个任务,所以它意味着等待。 -
我还有其他方法吗?
-
试试这个 nuget,因为它的 PCL 端口非常接近 System.Threading.Timer
https://www.nuget.org/packages/Amoenus.PclTimer/ -
@iamIcarus - 我会试一试
-
@iamIcarus - 你确定我能以同样的方式使用它吗?如上
标签: c# xamarin timer xamarin.ios portable-class-library