2015-11-28 145 views
0

我正在玩我的应用程序中的线程计时器。我的代码似乎工作正常,但计时器不会重复。它会运行一次,然后停止/挂起。我使用以下代码:Theading.Timer每x秒调用一个方法

new System.Threading.Timer(scrape, null, (this.timeout * 1000), System.Threading.Timeout.Infinite); 

this.timeout被设定为int,例如5(5分钟)。

我检查了文档,并且我看不到任何问题。任何帮助深表感谢。

+4

如果你没有参考它的计时器可以垃圾收集。 – erem

回答

2

您正在发送参数错误。

var timer = new System.Threading.Timer(scrape, null, 0, (this.timeout * 1000)); 

最后一个参数指定间隔。

另外5 * 1000毫秒是5秒而不是5分钟。如果你想5分钟,那么你必须乘以5 60000.

this.timeout * 60000 
+0

对不起,我的意思是把秒,而不是几分钟。 Appologies。 – BugHunterUK