How to save timers with connection to OrderId?

Posted by Adrian Serafin on Stack Overflow See other posts from Stack Overflow or by Adrian Serafin
Published on 2010-06-02T13:32:41Z Indexed on 2010/06/02 13:33 UTC
Read the original article Hit count: 282

Filed under:
|
|

Hi!

I have a system where clients can make orders. After making order they have 60 minutes to pay fot it before it will be deleted. On the server side when order is made i create timer and set elapsed time to 60 minutes

System.Timer.Timers timer = new System.Timers.Timer(1000*60*60);
timer.AutoReset = false;
timer.Elapsed += HandleElapsed;
timer.Start();

Because I want to be able to dispose timer if client decides to pay and I want to be able to cancel order if he doesn't I keep two Dictionaries:

Dictionary<int, Timer> _orderTimer;
Dictionary<Timer, int> _timerOrder;

Then when client pay's I can access Timer by orderId with O(1) thanks to _orderTimer dictionary and when time elapsed I can access order with O(1) thanks to _timerOrder dictionary.

My question is: Is it good aproach? Assuming that max number of rows I have to keep in dictionary in one moment will be 50000?

Maybe it would be better to derive from Timer class, add property called OrderId, keep it all in List and search for order/timer using linq?

Or maybe you I should do this in different way?

© Stack Overflow or respective owner

Related posts about c#

Related posts about mono