Sys增加设定任务周期的方法

This commit is contained in:
nnhy 2015-08-22 06:37:53 +00:00
parent 547e0759fd
commit 65d18e8727
3 changed files with 15 additions and 4 deletions

11
Sys.cpp
View File

@ -574,6 +574,17 @@ bool TSys::SetTask(uint taskid, bool enable, int usNextTime)
return true;
}
// 改变任务周期
bool TSys::SetTaskPeriod(uint taskid, Int64 period)
{
Task* task = Task::Get(taskid);
if(!task) return false;
task->Period = period;
return true;
}
void TSys::Start()
{
#if DEBUG

2
Sys.h
View File

@ -130,6 +130,8 @@ public:
void RemoveTask(uint taskid);
// 设置任务的开关状态同时运行指定任务最近一次调度的时间0表示马上调度
bool SetTask(uint taskid, bool enable, int usNextTime = -1);
// 改变任务周期
bool SetTaskPeriod(uint taskid, Int64 period);
void Start(); // 开始系统大循环
Func OnStart;
};

View File

@ -279,10 +279,9 @@ bool TinyClient::OnJoin(TinyMessage& msg)
Password.Show(true);
// 取消Join任务启动Ping任务
Task* task = Task::Get(_TaskID);
ushort time = Config.PingTime;
if(time < 5) time = 5;
task->Period = time * 1000000;
Sys.SetTaskPeriod(_TaskID, time * 1000000);
// 组网成功更新一次最后活跃时间
LastActive = Time.Current();
@ -307,8 +306,7 @@ void TinyClient::Ping()
debug_printf("%d 秒无法联系服务端可能已经掉线重启Join任务关闭Ping任务\r\n", off);
Task* task = Task::Get(_TaskID);
task->Period = 5000000;
Sys.SetTaskPeriod(_TaskID, 5000000);
Server = 0;
Password = 0;