pagra
pagra

Reputation: 665

Designating current delegate object

For example with a scheduler class like this:

class Scheduler
{
    public void Add(DateTime time, Action action);
    ...
}

I can plan a simple action like this:

Scheduler scheduler= new Scheduler();
scheduler.Add(someTime, delegate() { Console.WriteLine("Done!"); });

Now I want my action to replan itself later, so I write this:

scheduler.Add(someTime, delegate() { Console.WriteLine("Done!"); scheduler.Add(someTimeLater, !this current action!); });

But how can I designate !this current action! or code this in another way?

Upvotes: 0

Views: 56

Answers (1)

Servy
Servy

Reputation: 203814

You'll need to assign it to a variable to do this:

Action action = null;
action = () => 
{
    Console.WriteLine("Done!"); 
    scheduler.Add(someTimeLater, action);
};
scheduler.Add(someTime, action);

Upvotes: 2

Related Questions