views:

89

answers:

2

I don't understand why this code fails to measure when 4 hours has elapsed.

    if (guildVaultRunStarter.IsRunning)
    {
        if (guildVaultRunTimer.ElapsedMilliseconds > 4 * 60 * 60 * 1000) // 4 hours
        {
            guildVaultRunStarter.Reset();
            log("Its been over 4 hours - empty bags.");
            return true;
        }
        else
        {
            log("guildVaultRunTimer.ElapsedMilliseconds = " +
                guildVaultRunTimer.ElapsedMilliseconds.ToString() + ".");
        }
    }
    else
    {
        log("Start the 4 hour guild vault countdown.");
        guildVaultRunStarter.Reset();
        guildVaultRunStarter.Start();
    }

The logging shows this:

[8/23/2009 12:17:21 PM]:Start the 4 hour guild vault countdown.
...
[8/23/2009 12:26:53 PM]:guildVaultRunTimer.ElapsedMilliseconds = 0.
...
[8/23/2009 12:27:26 PM]:guildVaultRunTimer.ElapsedMilliseconds = 0.

Why is it always 0?

A: 

Where do you instantiate the timer and where/how is this bit of code called?

Paddy
When the class is started I have:private Stopwatch guildVaultRunStarter = new Stopwatch();The code is called when the character kills a mob and loots an item. Bags fill in 5 hours so the idea is to empty them in 4.
Patrick
+3  A: 

Is it just a typo between guildVaultRunTimer and guildVaultRunStarter?

i.e.

if (guildVaultRunStarter.ElapsedMilliseconds > ...

You never seem to start guildVaultRunTimer, after all.

Marc Gravell
/me shudders in shock and swears to never have such similar variable names again.Thanks!
Patrick