开发者

Implementing object timeout based on timespan

Hi guys I 开发者_开发知识库need to implement a way to timeout my objects without using a timer class that is base on specific timespan and last transaction date. Can anyone point a good implementation of this kind or a sample may be? By the way this is not a web application but a console app.

Edit 1:

Sorry I forgot to tell you guys some of my actual scenarios. I have different threads that produces objects that needs to be timeout if no events after x amount of time. I already have a working logic for this using timers but I wanted it to be more efficient and not use the threads on my thread pool ( since I'm using a timer then the object on WaitCallBack will be processed by an idle thread on my app domain thread pool ). I was thinking if I could just use a single thread to do this but I'm lost on how I will implement it. Hope some guys can out there can help me out thanks!


I can't see a way to do this without a timer of some sort.

You can subtract the last transaction date from DateTime.Now - use the resulting timespan with your specific timespan to get the number of milliseconds you need to initialize a timer with.


I have a feeling the Cache object may be able to help you out - even though it's not a web app, you can still use it by adding a reference to System.Web, or if you're in .NET 4, they've added it in System.Runtime.Caching.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜