I am looking for a way to quickly retrieve all items out of a list. This list contains time values, and i need everything before a specific time. Obviously a list which is ordered should be easy, once you find 1 item in the list with a higher value than what you've defined it can stop.
I found this ordered queue online which claims to be fast but it does not have a good method for finding all times up to a certain point.
If i knew of a way to make this method (a good and fast one) i would, but I have no idea what the best possible way would be.
I am currently using this queue as follows, which isn't the best way to use it (I would think):
while (mDisposing == false)
{
if (this.mIdleChoresRunning == true)
{
try
{
if ((mIdleChoreQueue.First != null) && (Timing.IsTimeOutByTicksNow(mIdleChoreQueue.First.AddTime, mIdleChoreQueue.First.WaitTime)))
{
//var item = mIdleChoreQueue.Dequeue();
var chore = mIdleChores[mIdleChoreQueue.First.IdleChoreIdentification];
mIdleChoreQueue.First.AddTime = Environment.TickCount;
mIdleChoreQueue.First.WaitTime = chore.IdleMiliSeconds;
mTaskQueue.EnqueueTask(() =>
//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);
}
}
To clarify I do not care about the type of collection, all I want is a faster way for getting my items (and executing them) than:
mIdleChoreList.Where(x => Timing.IsTimeOutByTicksNow(x.AddTime, x.WaitTime));
Because a .Where() operation is really slow.