Hi,
I've duplicated the disguisePersistance Timer to create a new taxPersistance Timer which counts taxes, but when i reboot the server this timer doesn't restart and the timer.Next is 01/01/0001... why?

Code:
using System;
using System.Collections.Generic;
using Server;
using Server.Mobiles;
using Server.Network;

namespace Server.Items
{
    public class TaxPersistance : Item
    {
        private static TaxPersistance m_Instance;

        public static TaxPersistance Instance{ get{ return m_Instance; } }

        public override string DefaultName
        {
            get { return "Tax Persistance - Internal"; }
        }

        public TaxPersistance() : base( 1 )
        {
            Movable = false;
          
            if ( m_Instance == null || m_Instance.Deleted )
                m_Instance = this;
            else
                base.Delete();
        }

        public TaxPersistance( Serial serial ) : base( serial )
        {
            m_Instance = this;
        }

        public override void Serialize( GenericWriter writer )
        {
            base.Serialize( writer );

            writer.Write( (int) 0 ); // version
          
            int timerCount = TaxTimers.Timers.Count;
          
            writer.Write( timerCount );
              
            foreach ( KeyValuePair<CityStone, Timer>entry in TaxTimers.Timers )
            {
                CityStone c = entry.Key;

                writer.Write( (Item)c );
                writer.Write( entry.Value.Next - DateTime.UtcNow );
            }
        }

        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize( reader );

            int version = reader.ReadInt();

            switch ( version )
            {
                case 0:
                {
                    int count = reader.ReadInt();
                                  
                    for ( int i = 0; i < count; ++i )
                    {
                        CityStone c = reader.ReadItem() as CityStone;
                        TaxTimers.CreateTimer( c, c.Taxes, reader.ReadTimeSpan() );
                    }

                    break;
                }
            }
        }

        public override void Delete()
        {
        }
    }
}

This is the other part:

Code:
public class TaxTimers
    {
        public static void Initialize()
        {
            new TaxPersistance();
        }
       
        private class InternalTimer : Timer
        {
            private CityStone m_CityStone;
            private Dictionary<int, int> m_Dict;
            private TimeSpan m_Delay;
           
            public InternalTimer( CityStone stone, TimeSpan delay, Dictionary<int, int> dict) : base( delay )
            {
                m_CityStone = stone;
                m_Delay = delay;
                m_Dict = dict;
                Priority = TimerPriority.OneSecond;
            }

            protected override void OnTick()
            {
                if( m_CityStone.Tax > 0 )
                {
                    TaxTimers.RemoveTimer( m_CityStone );               
                    TaxTimers.CreateTimer( m_CityStone, m_CityStone.Taxes, TimeSpan.FromMinutes( 1.0 ) );
                    TaxTimers.StartTimer( m_CityStone );
                }
                else
                {
                    TaxTimers.RemoveTimer( m_CityStone );   
                }
            }
        }
       
        public static void CreateTimer( CityStone stone, Dictionary<int, int> dict, TimeSpan delay )
        {
            if ( stone != null )
                if ( !m_Timers.ContainsKey( stone ) )
                    m_Timers[stone] = new InternalTimer( stone, delay, dict );
        }
       
        public static void StartTimer( CityStone stone )
        {
            Timer t = null;
            m_Timers.TryGetValue(stone, out t);
                               
            if ( t != null )
                t.Start();  
        }

        public static bool IsTaxed( CityStone stone )
        {
            return m_Timers.ContainsKey( stone );
        }

        public static bool StopTimer( CityStone stone )
        {
            Timer t = null;
            m_Timers.TryGetValue(stone, out t);

            if ( t != null )
            {
                t.Delay = t.Next - DateTime.UtcNow;
                t.Stop();
            }

            return ( t != null );
        }
       
        public static bool RemoveTimer( CityStone stone )
        {
            Timer t = null;
            m_Timers.TryGetValue(stone, out t);

            if ( t != null )
            {               
                stone.PublicOverheadMessage( MessageType.Regular, 0x3B2, false, "Tax!" );
               
                List<int> aspect = new List<int>();
                List<int> taxes = new List<int>();

                foreach( KeyValuePair<int, int> kvp in stone.Taxes )
                {
                    aspect.Add(kvp.Key);
                    taxes.Add(kvp.Value - 1);
                }

                for(int k = 0; k < stone.Taxes.Count; k++)
                {
                    stone.UpdateTaxes( aspect[k], taxes[k] );
                }
               
                t.Stop();
                m_Timers.Remove(stone);
            }
           
            return ( t != null );
        }
       
        public static TimeSpan TimeRemaining( CityStone stone )
        {
            Timer t = null;
            m_Timers.TryGetValue(stone, out t);

            if ( t != null )
            {
                return t.Next - DateTime.UtcNow;
            }
           
            return TimeSpan.Zero;
        }
       
        private static Dictionary<CityStone, Timer> m_Timers = new Dictionary<CityStone, Timer>();

        public static Dictionary<CityStone, Timer> Timers
        {
            get { return m_Timers; }
        }
    }
 
Solved changing this:
Code:
for ( int i = 0; i < count; ++i )
{
     CityStone c = reader.ReadItem() as CityStone;
     TaxTimers.CreateTimer( c, c.Taxes, reader.ReadTimeSpan() );
}
in:
Code:
for ( int i = 0; i < count; ++i )
{
     CityStone c = reader.ReadItem() as CityStone;
     TaxTimers.CreateTimer( c, c.Taxes, reader.ReadTimeSpan() );
     TaxTimers.StartTimer( c );
 }
 
Back