[英]How to call a method every x seconds for x time in Xamarin Forms?
[英]Theading.Timer to call a method every x number of seconds
我在應用程序中使用線程計時器。 我的代碼似乎可以正常工作,但計時器不會重復。 它將運行一次,然后停止/掛起。 我正在使用以下代碼:
new System.Threading.Timer(scrape, null, (this.timeout * 1000), System.Threading.Timeout.Infinite);
this.timeout
設置為int
,例如5
(5分鍾)。
我檢查了文檔,但看不到任何問題。 任何幫助深表感謝。
您發送的參數錯誤。
var timer = new System.Threading.Timer(scrape, null, 0, (this.timeout * 1000));
最后一個參數指定間隔。
5 * 1000毫秒也是5秒而不是5分鍾。 如果要5分鍾,則必須將5乘以60000。
this.timeout * 60000
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.