【问题标题】:System.Threading.Timer equivalent in PCLPCL 中的 System.Threading.Timer 等效项
【发布时间】: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


【解决方案1】:

你可以这样开始:

System.Threading.Tasks.Task.Delay(10000) 

background worker 中。 如果计时器完成,您可以提供反馈,以便您可以调用您的函数。 这种方式不会阻塞你的 UI...

【讨论】:

  • 我相信后台工作者可用于Windows桌面应用程序开发
猜你喜欢
  • 1970-01-01
  • 2014-05-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-12-16
  • 2018-06-25
  • 2015-07-09
相关资源
最近更新 更多