I ask, although I doubt that there is such a system.
Basically, I need to plan tasks at some point in the future (usually no more than a few seconds or maybe minutes from this time), and have a way to cancel this request if it's too late.
Those. code that will look like this:
var x = Scheduler.Schedule(() => SomethingSomething(), TimeSpan.FromSeconds(5)); ... x.Dispose();
Is there such a system in .NET? Is there anything in TPL that can help me?
I need to run such future actions from different instances in the system here and rather avoid each such instance of the class in order to have my own thread and deal with it.
Also note that I do not want this (or similar, for example, through Tasks):
new Thread(new ThreadStart(() => { Thread.Sleep(5000); SomethingSomething(); })).Start();
There may be several such tasks to perform, they do not need to be performed in any particular order, except for those close to their deadline, and it does not really matter that they have something like a real-time performance concept. I just want to avoid turning a separate thread for each such action.
source share