简体   繁体   English

TimerCallback - 可以改变时间吗?

[英]TimerCallback - Possible to change time?

I have this function... 我有这个功能......

Instance(uint InstanceId) { }

Inside it is this code... 里面是这个代码......

        mUpdater = new Timer(new TimerCallback(PerformUpdate), null, TimeSpan.FromMilliseconds(500), TimeSpan.FromMilliseconds(500));

It refreshes PerformUpdate every 500 milliseconds 它每500毫秒刷新一次PerformUpdate

In PerformUpdate i have a IF statement to calculate if a user has a specfic variable defined. 在PerformUpdate中,我有一个IF语句来计算用户是否定义了specfic变量。 How would I make it so if a user has the variable, then it only refreshes every 300 milliseconds instead of 500. 如果用户拥有变量,我将如何制作它,然后它每300毫秒而不是500毫秒刷新一次。

Oh and it cannot be set inside the Instance function as its a per user command and Instance is for every user. 哦,它不能在Instance函数中设置,因为它是一个每用户命令,Instance适用于每个用户。

Help would be much appreciated! 非常感谢帮助!

This looks like it's for the System.Threading.Timer , not System.Timers.Timer , correct? 这看起来像是System.Threading.Timer ,而不是System.Timers.Timer ,对吗? You can call the Change method on a System.Threading.Timer to change its start time and interval. 您可以在System.Threading.Timer上调用Change方法来更改其开始时间和间隔。

var variableDefined = true;        
var threadingCallback = new System.Threading.TimerCallback((o) => { });
var threadingTimer = new System.Threading.Timer(threadingCallback, null, 0, 500);
if (variableDefined) {
    threadingTimer.Change(0, 300);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM