Raised This Month: $12 Target: $400
 3% 

[Question] safely KillTimer()


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
jopmako
Senior Member
Join Date: Jul 2006
Location: QQ:331537639
Old 03-18-2007 , 08:04   [Question] safely KillTimer()
Reply With Quote #1

Can we remove error log when KillTimer() using to a invalid handle?
Most time we don't need this log.
__________________
QQ31537639
jopmako is offline
Send a message via MSN to jopmako
BAILOPAN
Join Date: Jan 2004
Old 03-18-2007 , 12:33   Re: [Question] safely KillTimer()
Reply With Quote #2

Why would you call KillTimer on an invalid handle? If you're saving the timer Handle and you know the timer is gone, you should set it to 0 (or INVALID_HANDLE) to mark it as invalid.
__________________
egg
BAILOPAN is offline
jopmako
Senior Member
Join Date: Jul 2006
Location: QQ:331537639
Old 03-18-2007 , 13:58   Re: [Question] safely KillTimer()
Reply With Quote #3

Code:
new Handle:hTimer[65]
 
public OnClientPutInServer(client)
{
   hTimer[client] = CreateTimer(GetRandomFloat(5.0, 10.0), welcome_msg, client);
}
 
public OnClientDisconnect(client)
{
   if (IsValidHandle(hTimer[client]))
   {
      KillTimer(hTimer[client], true);
      hTimer[client] = INVALID_HANDLE;
   }
}
 
public Action:welcome_msg(Handle:timer, client)
{
   // coding...
 
   hTimer[client] = INVALID_HANDLE;
}
Is this right?
thank you.
__________________
QQ31537639
jopmako is offline
Send a message via MSN to jopmako
BAILOPAN
Join Date: Jan 2004
Old 03-18-2007 , 14:06   Re: [Question] safely KillTimer()
Reply With Quote #4

This would fix your problem:
Code:
new Handle:hTimer[65]   public OnClientPutInServer(client) {    hTimer[client] = CreateTimer(GetRandomFloat(5.0, 10.0), welcome_msg, client); }   public OnClientDisconnect(client) {    if (hTimer[client] != INVALID_HANDLE)    {       KillTimer(hTimer[client]);       hTimer[client] = INVALID_HANDLE;    } }   public Action:welcome_msg(Handle:timer, client) {    // coding...      hTimer[client] = INVALID_HANDLE; }

Note that KillTimer()'s second parameter must be false... autoClose is only if you pass a Handle to the timer; you passed a client index.
__________________
egg
BAILOPAN is offline
jopmako
Senior Member
Join Date: Jul 2006
Location: QQ:331537639
Old 03-18-2007 , 14:18   Re: [Question] safely KillTimer()
Reply With Quote #5

oh, I see.
thanks a lot.
__________________
QQ31537639
jopmako is offline
Send a message via MSN to jopmako
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 20:41.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode