Go Back   RunUO - Ultima Online Emulation > RunUO > RunUO Post Archive

RunUO Post Archive The Archvie

Reply
 
Thread Tools Display Modes
Old 01-07-2004, 04:20 PM   #1 (permalink)
Moderate
 
David's Avatar
 
Join Date: Nov 2002
Location: USA
Posts: 6,598
Default A simple Timer with comments

Here is a very basic Timer with a lot of comments. Hopefully this will help some that are struggling with timers.

PHP Code:
// Here we declare the timer class
private class MyTimer Timer
{
    
// Variables declared here will be accessible in both 
    // the initializer and OnTick methods

    
private Mobile m_player;

    
// This is where the timer is initialized
    // any required parameters are specified here ( i.e. Mobile m )
    // in this case the base class is called with two TimeSpans
    // The first is the initial delay before the first time OnTick is fired
    // The second (optional) is the delay between each subsequent OnTick
    // If the second is omitted, OnTick will only fire once.

    
public MyTimerMobile m ) : baseTimeSpan.FromSeconds60 ), TimeSpan.FromSeconds30 ) )
    {
        
// This (optional) sets the "resolution" of the timer
        // In this case it is checked once a second

        
Priority TimerPriority.OneSecond;

        
// Here we save the reference to a Mobile
        // that was passed to the initializer.

        
m_player m;
    }

    
// This method is where the actual work gets done
    
protected override void OnTick()
    {
        
// Since it has been a period of time, it is possible the 
        // Mobile was deleted. This could crash the shard, so we check.

        
if ( ( m_player != null ) && ( !m_player.Deleted ) )
        {
            
// Do whatever here.

            
m_player.SendMessage"The Timer fired!" );
        }

        
// otherwise the Mobile is gone, so stop the timer.

        
else Stop();
    }


TimerPriority members
EveryTick
TenMS
TwentyFiveMS
FiftyMS
TwoFiftyMS
OneSecond
FiveSeconds
OneMinute


TimeSpan methods (short list)
FromDays ()
FromHours ()
FromMilliseconds ()
FromMinutes ()
FromSeconds ()
FromTicks ()
Zero
__________________
David Forum Moderator
The RunUO.com Forum Moderator Team

Forum Rules and Guidelines
RunUO Forum Search Engine
Download RunUO 2.0 RC2
David is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5