I have created a class which handles (what i call) idle chores. These chores need to be executed every x seconds (x is random every time but within a certain range defined in the settings)With this code review I'm hoping to find inefficiencies in the code, I need to optimise this because the performance is somewhat lacking when it goes over 300 chores a second.The 'main' method is ExecuteIdleChores() this is where everything is executed and new times (for when it needs to be executed again) are calculated.The code:/// <summary>/// Contains the information about the simulation./// </summary>public class Simulation : IDisposable{    #region Fields    private static readonly ILog mLogger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);    private Dictionary<Guid, IdleChore> mIdleChores = new Dictionary<Guid, IdleChore>();    private FastPriorityQueue<IdleSimulationArguments> mIdleChoreQueue = new FastPriorityQueue<IdleSimulationArguments>(2048);    private bool mIdleChoresRunning = true;    private bool mDisposing = false;    //private ConcurrentDictionary<Guid, IdleSimulationArguments> mCommandsForModule = new ConcurrentDictionary<Guid, IdleSimulationArguments>();    private Task mReportReceivedMessagesTask = null;    #endregion    #region Constructors    /// <summary>    /// Initializes a new instance of the <see cref=Simulation/> class.    /// </summary>    public Simulation()    {        mReportReceivedMessagesTask = Task.Factory.StartNew(() => ExecuteIdleChores(), TaskCreationOptions.LongRunning);    }    #endregion    #region Properties    /// <summary>    /// Gets the idle tasks.    /// </summary>    /// <value>The idle tasks.</value>    public Dictionary<Guid, IdleChore> IdleChores    {        get        {            return mIdleChores;        }    }    #endregion    /// <summary>    /// Register a simulation context (Module) for the idle chores.    /// </summary>    /// <param name=context>The context needed to run the chore.</param>    /// <param name=address>The address of the module.</param>    public void RegisterModuleForIdleChores(SimulationContext context, string address)    {        if (mIdleChoreQueue.Any(x => x.Address == address) == false)        {            foreach (var idleChore in this.IdleChores)            {                var arguments = new IdleSimulationArguments();                arguments.AddTime = Environment.TickCount;                arguments.Context = context;                arguments.IdleChoreIdentification = idleChore.Key;                arguments.WaitTime = idleChore.Value.IdleMiliSeconds;                arguments.Address = address;                mIdleChoreQueue.Enqueue(arguments, arguments.AddTime + arguments.WaitTime);            }        }    }    /// <summary>    /// Deregister the module from this simulation.    /// </summary>    /// <param name=address>The address of the module.</param>    public void DeregisterModuleForIdleChores(string address)    {        var argumentsToRevove = mIdleChoreQueue.Where(x => x.Address == address);        foreach (var argument in argumentsToRevove)        {            mIdleChoreQueue.Remove(argument);        }    }    /// <summary>    /// Dergeister all the modules for this simulation.    /// </summary>    public void DergeisterAllModules()    {        mIdleChoreQueue.Clear();    }    /// <summary>    /// Reports the received messages from the queue.    /// </summary>    private void ExecuteIdleChores()    {        while (mDisposing == false)        {            if (this.mIdleChoresRunning == true)            {                try                {                    if ((mIdleChoreQueue.First != null) && (Timing.IsTimeOutByTicksNow(mIdleChoreQueue.First.AddTime, mIdleChoreQueue.First.WaitTime)))                    {                        var chore = mIdleChores[mIdleChoreQueue.First.IdleChoreIdentification];                        mIdleChoreQueue.First.AddTime = Environment.TickCount;                        mIdleChoreQueue.First.WaitTime = chore.IdleMiliSeconds;                        Task.Factory.StartNew(() =>                        {                            chore.Execute(mIdleChoreQueue.First.Context);                        });                        mIdleChoreQueue.UpdatePriority(mIdleChoreQueue.First, mIdleChoreQueue.First.AddTime + mIdleChoreQueue.First.WaitTime);                    }                    else                    {                        Thread.Sleep(10);                    }                }                catch (Exception exception)                {                    mLogger.Error(ExecuteIdleChores() EXCEPTION, exception);                }            }            else            {                Thread.Sleep(100);            }        }    }    #region Implementation of IDisposable interface    /// <summary>    /// Disposes resources.    /// </summary>    /// <param name=disposing>True to dispose managed resources.</param>    protected virtual void Dispose(bool disposing)    {        // Dispose managed resources.        if ((disposing == true) && (mDisposing == false))        {            mDisposing = true;            mIdleChoresRunning = false;            if (mReportReceivedMessagesTask != null)            {                mReportReceivedMessagesTask.Wait();                mReportReceivedMessagesTask.Dispose();                mReportReceivedMessagesTask = null;            }        }    }    /// <summary>    /// Disposes resources.    /// </summary>    public void Dispose()    {        this.Dispose(true);        GC.SuppressFinalize(this);    }    #endregion}In case someone is interested the queue I'm using is from here, I used to just put it in a List and use the linq .where() statement to get a list of all the chores that have expired and need to be executed (like this: list.Where(x => Timing.IsTimeOutByTicksNow(x.AddTime, x.WaitTime)) but I thought the .where made it quite slow.an over simplified version of an idle chore (which can be defined in xml and read into C# code) that would send the 'Message' to some server every 1 to 2 seconds (a random milisecond value is calculated between the min and max values which becomse the waittime in the code)<IdleChore  MinimumIdleTime=00:00:01 MaximumIdleTime=00:00:02>    <OptionMessage Message=Some message to send /></IdleChore>
A class for handling chores
c#;performance;multithreading